home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / sbin / checkinstall next >
Encoding:
Text File  |  2006-08-20  |  72.2 KB  |  2,603 lines

  1. #!/bin/sh
  2. ##############################################################################
  3. #         $Id: checkinstall,v 1.6.0.57 2005/06/24 03:51:38 izto Exp $ 
  4. #                           ########################                         
  5. #                                                                            
  6. #
  7. #                             CheckInstall v1.6.0
  8. #
  9. #  Installs a compiled program from the program's source directory using     
  10. #  "make install" or any other command supplied on checkinstall's command  
  11. #  line. checkinstall will create a Slackware, RPM or Debian compatible package
  12. #  named after the source directory's name and install it using your standard  
  13. #  package administration utilities.                                      
  14. #                                                                            
  15. #  This version of checkinstall needs enough free space on the partition     
  16. #  holding the temp dir (see BASE_TEMP_DIR below) to write there a temporary 
  17. #  copy of the package.              
  18. #                                                                            
  19. #  Copyright (C) 2004 Felipe Eduardo Sanchez Diaz Duran <izto@asic-linux.com.mx>
  20. #  
  21. #
  22. #    This program is free software; you can redistribute it and/or modify
  23. #    it under the terms of the GNU General Public License as published by
  24. #    the Free Software Foundation; either version 2 of the License, or
  25. #    (at your option) any later version. 
  26. #
  27. #    This program is distributed in the hope that it will be useful,
  28. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  30. #    GNU General Public License for more details.
  31. #
  32. #    You should have received a copy of the GNU General Public License
  33. #    along with this program; if not, write to the Free Software
  34. #    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  35. #
  36. ############################################################################
  37.  
  38.  
  39. # Trap the INT signal (ctrl-c, for example)
  40. trap trapint 2
  41.  
  42. CHECKINSTALL_VERSION=1.6.0
  43.  
  44.  
  45.  
  46.  
  47. # gettext variables
  48. export TEXTDOMAINDIR=/usr/share/locale
  49. export TEXTDOMAIN=checkinstall
  50.  
  51. # .spec file path
  52. DIRECTORIO_FUENTE=`pwd`
  53. PKG_BASENAME="`basename \"$DIRECTORIO_FUENTE\"`"
  54. SPEC_PATH=${PKG_BASENAME}.spec
  55.  
  56. #############################################################################
  57.                            # Function definitions #
  58.                            ########################
  59.  
  60.  
  61. # Vefify that we have gettext available
  62. gettext "Bye." &> /dev/null
  63.  
  64. if [ $? -gt 0 ]; then
  65.    alias ck_gettext="echo -e"
  66. else
  67.    alias ck_gettext="gettext -s --"
  68. fi
  69.  
  70. ## gettext echo with newline at the end
  71. function echog() {
  72.    local format="$1\n"
  73.    shift
  74.    printf -- "$(ck_gettext "$format")" "$@" >&2
  75. }
  76.  
  77. ## gettext echo with NO newline at the end
  78. function   echogn() {
  79.    local format="$1"
  80.    shift
  81.    printf -- "$(ck_gettext "$format")" "$@" >&2
  82. }
  83.  
  84.  
  85.  
  86. function ckversion {
  87.    echo
  88.    echo "checkinstall $CHECKINSTALL_VERSION, Copyright 2002 Felipe Eduardo Sanchez Diaz Duran"
  89.    echog "           This software is released under the GNU GPL."
  90. }
  91.  
  92.  
  93.  
  94. function usage() {
  95.  
  96. # If the user has a default pager defined in the PAGER environment variable,
  97. # we'll use that. If not, we'll use "more".
  98.  
  99. ! [ "$PAGER" ] && PAGER=more
  100.  
  101.  
  102.    (
  103.    ckversion
  104.    echo
  105.    echog "Usage: checkinstall [options] [command [command arguments]]"
  106.    echog "Options:"
  107.    echo
  108.    echog "*Package type selection*"
  109.    echo
  110.    echog "-t,--type=<slackware|rpm|debian> Choose packaging system"
  111.    echog "-S                               Build a Slackware package"
  112.    echog "-R                               Build a RPM package"
  113.    echog "-D                               Build a Debian package"
  114.    echo
  115.    echog "*Install options*"
  116.    echo
  117.    echog "--install=<yes|no>             Toggle created package installation"
  118.    echog "--fstrans=<yes|no>             Enable/disable the filesystem translation code"
  119.    echo
  120.    echog "*Scripting options*"
  121.    echo
  122.    echog "-y, --default                  Accept default answers to all questions"
  123.    echog "--pkgname=<name>               Set name"
  124.    echog "--pkgversion=<version>         Set version"
  125.    echog "-A, --arch, --pkgarch=<arch>   Set architecture"
  126.    echog "--pkgrelease=<release>         Set release"
  127.    echog "--pkglicense=<license>         Set license"
  128.    echog "--pkggroup=<group>             Set software group"
  129.    echog "--pkgsource=<source>           Set source location"
  130.    echog "--pkgaltsource=<altsource>     Set alternate source location"
  131.    echog "--pakdir=<directory>           The new package will be saved here"
  132.    echog "--maintainer=<email addr>      The package maintainer (.deb)"
  133.    echog "--provides=<list>              Features provided by this package (.rpm)"
  134.    echog "--requires=<list>              Features required by this package (.rpm)"
  135.    echog "--rpmflags=<flags>             Pass this flags to the rpm installer"
  136.    echog "--rpmi                         Use the -i flag for rpm when installing a .rpm"
  137.    echog "--rpmu                         Use the -U flag for rpm when installing a .rpm"
  138.    echog "--dpkgflags=<flags>            Pass this flags to the dpkg installer"
  139.    echog "--spec=<path>                  .spec file location"
  140.    echog "--nodoc                        Do not include documentation files"
  141.    echo
  142.    echog "*Info display options*"
  143.    echo
  144.    echog "-d<0|1|2>                      Set debug level"
  145.    echog "-si                            Run an interactive install command"
  146.    echog "--showinstall=<yes|no>         Toggle interactive install command"
  147.    echog "-ss                            Run an interactive Slackware installation script"    
  148.    echog "--showslack=<yes|no>           Toggle interactive Slackware installation script"
  149.    echo
  150.    echog "*Package tuning options*"
  151.    echo
  152.    echog "--autodoinst=<yes|no>          Toggle the creation of a doinst.sh script"
  153.    echog "--strip=<yes|no>               Strip any ELF binaries found inside the package"
  154.    echog "--stripso=<yes|no>             Strip any ELF binary libraries (.so files)" 
  155.    echog "--addso=<yes|no>               Search for any shared libs and add"
  156.    echog "                               them to /etc/ld.so.conf"
  157.    echog "--reset-uids=<yes|no>          Reset perms for all files/dirs to 755 and"
  158.    echog "                               the owner/group for all dirs to root.root"
  159.    echog "--gzman=<yes|no>               Compress any man pages found inside the package"
  160.    echog "--docdir=<path>                Where to put documentation files"
  161.    echog "--umask=<mask>                 Set the umask value"
  162.    echog "--exclude=<file|dir[,...]>     Exclude these files/directories from the package"
  163.    echog "--include=<listfile>           Force the inclusion in the package of the"
  164.    echog "                               files/dirs listed in \"listfile\""
  165.    echog "--inspect                      Inspect the package's file list"
  166.    echog "--review-spec                  Review the spec file before creating a .rpm"
  167.    echog "--review-control               Review the control file before creating a .deb"
  168.    echog "--newslack                     Use the new (8.1+) Slackware description format"
  169.    echog "                               (\"--newslack\" implies \"-S\")"
  170.    echog "--with-tar=/path/to/tar        Manually set the path to the tar binary" 
  171.    echog "                               in this system"
  172.    echo
  173.    echog "*Cleanup options*"
  174.    echo
  175.    echog "--deldoc=<yes|no>              Delete doc-pak upon termination"
  176.    echog "--deldesc=<yes|no>             Delete description-pak upon termination"
  177.    echog "--delspec=<yes|no>             Delete spec file upon termination"
  178.    echog "--bk                           Backup any overwritten files"
  179.    echog "--backup=<yes|no>              Toggle backup"
  180.    echo
  181.    echog "*About CheckInstall*"
  182.    echo
  183.    echog "--help, -h                     Show this message"
  184.    echog "--copyright                    Show Copyright information"
  185.    echog "--version                      Show version information"
  186.    echo
  187.    ) | $PAGER
  188.    exit 1
  189. }
  190.  
  191. function help_notice() {
  192.  
  193. echo
  194. echog "Use --help or -h to get more information"
  195. echo
  196. exit 1 
  197.  
  198. }
  199.  
  200. function boolean_usage() {
  201.    echo
  202.    echog "%s is an invalid value for %s" "$2" "$1"
  203.    help_notice
  204.    exit 1
  205. }
  206.  
  207.  
  208. # 001117-BaP: Define a function or two
  209.  
  210. function yorn {
  211.  
  212.  
  213.    if [ "$1" ]; then     # If there is no default value specified
  214.        DEFAULTYN="$1"     # then the default is "y"
  215.     else
  216.        DEFAULTYN="y"
  217.     fi
  218.     DEFAULTYN=`echo $DEFAULTYN | tr 'A-Z' 'a-z'`
  219.  
  220.     if [ "$DEFAULTYN" = "y" ]; then  
  221.        echo -n " [y]: "              # Print the default option
  222.     else
  223.        echo -n " [n]: "
  224.     fi
  225.     
  226. if [ $ACCEPT_DEFAULT -eq 0 ]; then     # Should we accept all the defaults?
  227.  
  228.     read YN
  229.     YN=`echo $YN | tr 'A-Z' 'a-z'`
  230.     ! [ "$YN" ] && YN=$DEFAULTYN          # If the user pressed ENTER then 
  231.  
  232. else
  233.    YN=$DEFAULTYN
  234.    echo $YN
  235. fi
  236.  
  237.     if [ "$YN" = "y" ] ;then    # We return something useful for a 
  238.        return 0                 # simpler sintax ahead (12/dic/2000-Izto)
  239.     else
  240.        return 1
  241.     fi
  242.  
  243.  
  244. }
  245.  
  246.  
  247.  
  248. # dec/10/2000-Izto
  249. # Prints OK or FAILED! depending on previous command return value
  250.  
  251. function okfail () {
  252.  if [ $? -gt 0 ]; then
  253.     echog ' FAILED!'
  254.     return 1
  255.  else
  256.     echog 'OK'
  257.     return 0
  258.  fi
  259. }
  260.  
  261. function restore_backup {
  262.  # If we have translation turned on then we didn't do a backup
  263.  if [ "${TRANSLATE}" = "1" ]; then return 0; fi
  264.  
  265.  # Else, restore the backup if it exists
  266.  
  267.  rm -rf ${TMP_DIR}/BACKUP/no-backup &> /dev/null
  268.  
  269.  ls ${TMP_DIR}/BACKUP/*  &> /dev/null
  270.  if [ $? -eq 0 ]; then
  271.     echogn "Restoring overwritten files from backup..."
  272.     cd ${TMP_DIR}/BACKUP
  273.        $TAR -cpf - . | $TAR -f - -xvpC / &> /dev/null
  274.     okfail
  275.     echo
  276.  fi
  277.  
  278.  
  279. function trapint {
  280.  echo
  281.  echo
  282.  echog "*** SIGINT received ***"
  283.  cleanup
  284. }
  285.  
  286. function cleanup {
  287.  echo
  288.  restore_backup
  289.  echogn "Cleaning up..."
  290.  cd "$DIRECTORIO_FUENTE"
  291.  rm -rf ${TMP_DIR}
  292.  rm -f "$BUILDROOT"
  293.  rm -f "${RPMSOURCEDIR}/SOURCES/${PKG_BASENAME}.tgz"
  294.  rm -f checkinstall-debug*
  295.  
  296.  # If we had a pre-existing postinstall-pak, we keep it as it was.
  297.  if [ -f ${DIRECTORIO_FUENTE}/postinstall-pak.tmp ]; then
  298.     mv ${DIRECTORIO_FUENTE}/postinstall-pak.tmp ${DIRECTORIO_FUENTE}/postinstall-pak
  299.  fi
  300.  
  301.  true; okfail
  302.  echo
  303.  echog "Bye."
  304.  echo
  305.  exit 1
  306. }
  307.  
  308. # Function to copy a directory with permissions, honours setuid, setgid,
  309. # sticky bits, owner, group etc.
  310. #
  311. # A bit lengthy and slow but very few directories in the largest of
  312. # packages have to be copied like this.
  313.  
  314. function  dircopy() {
  315.    src_dir="$1" dest_dir="$2"
  316.    getflags() {
  317.      col=$1 dir="$2"
  318.      permissions="`ls -ld "$dir" | awk '{print $1}'`"
  319.      mask="."
  320.      bit=2
  321.      while [ $bit -lt $col ]; do mask="$mask."; bit=`expr $bit + 1`; done
  322.      mask="$mask\(.\)"
  323.      bit=$col
  324.      while [ $bit -lt 10 ]; do mask="$mask."; bit=`expr $bit + 1`; done
  325.      permission="`echo $permissions | sed "s/$mask/\1/" | grep -v -- '-'`"
  326.      case "$permission" in
  327.        s) echo "xs";; S) echo "s";; t) echo "xt";; T) echo "t";;
  328.        *) echo $permission;;
  329.      esac
  330.    }
  331.    col=2 chmod_args=""
  332.    set=u flags=""
  333.    while [ $col -le 4 ]; do
  334.      flags="$flags`getflags $col "$src_dir"`"; col=`expr $col + 1`
  335.    done
  336.    [ -n "$flags" ] && {
  337.      chmod_args="$set+$flags"
  338.    }
  339.    set=g flags=""
  340.    while [ $col -le 7 ]; do
  341.      flags="$flags`getflags $col "$src_dir"`"; col=`expr $col + 1`
  342.    done
  343.    [ -n "$flags" ] && {
  344.      [ -n "$chmod_args" ] && chmod_args="$chmod_args,"
  345.      chmod_args="$chmod_args$set+$flags"
  346.    }
  347.    set=o flags=""
  348.    while [ $col -le 10 ]; do
  349.      flags="$flags`getflags $col "$src_dir"`"; col=`expr $col + 1`
  350.    done
  351.    [ -n "$flags" ] && {
  352.      [ -n "$chmod_args" ] && chmod_args="$chmod_args,"
  353.      chmod_args="$chmod_args$set+$flags"
  354.    }
  355.    [ -d "$dest_dir" ] || {
  356.      mkdir -p "$dest_dir"
  357.      chmod 700 "$dest_dir"
  358.    }
  359.    [ -n "$chmod_args" ] && chmod $chmod_args "$dest_dir"
  360.    chown "`ls -ld "$src_dir" | awk '{print $3}'`" "$dest_dir"
  361.    chgrp "`ls -ld "$src_dir" | awk '{print $4}'`" "$dest_dir"
  362.  }
  363.  
  364. #
  365. # Read spec file if it exists or (pre)set variables if they don't exist
  366. #
  367.  
  368. function getparameter () {
  369.  
  370.    RES=`egrep "$1" < ${SPEC_PATH} \
  371.     | cut -f2 -d: | sed 's/^ *//g' | sed 's/ *$//g' `
  372.    shift
  373.    echo "$RES" | sed 's/^ *//g' | sed 's/ *$//g' 
  374.  
  375. }
  376.  
  377.  
  378.  
  379.                       #################################
  380.                       # Function definition ends here #
  381. #############################################################################
  382.  
  383. # Show the version information
  384. ckversion
  385. echo
  386.  
  387. if ! [ -f /etc/checkinstall/checkinstallrc ]; then
  388.    echog "The checkinstallrc file was not found at:\n/etc/checkinstall/checkinstallrc"
  389.    echo
  390.    echog "Assuming default values."
  391. else
  392. # Get our default settings from the rc file
  393. source /etc/checkinstall/checkinstallrc
  394. fi
  395.  
  396.  
  397. # Arguments parsing
  398.  
  399. CKNAME=`basename "$0"`
  400. PARAMS=`getopt -a -n $CKNAME -o +d:DA:t:RShHy -l arch:,type:,si,showinstall::,ss,showslack::,deldoc::,delspec::,deldesc::,strip::,addso::,install::,stripso::,gzman::,bk,backup::,autodoinst::,reset-uids::,fstrans::,spec:,exclude:,include:,pkgname:,pkgversion:,pkgrelease:,pkglicense:,pkggroup:,pkgsource:,pkgaltsource:,pakdir:,docdir:,requires:,provides:,maintainer:,dpkgflags:,rpmflags:,pkgarch:,umask:,with-tar:,inspect,review-spec,review-control,newslack,help,nodoc,rpmi,rpmu,version,copyright,default -- "$@"`
  401.  
  402. [ $? -gt 0 ] && help_notice
  403.  
  404. eval set -- $PARAMS
  405.  
  406. while [ "$1" != "--" ]; do
  407.    case "$1" in
  408.       -h|-H|--help)
  409.          usage;;
  410.       -d)
  411.          shift
  412.          case `eval echo $1` in
  413.             0) DEBUG=0;;
  414.             1|'') DEBUG=1;;
  415.             2) DEBUG=2;;
  416.             3) DEBUG=3;;
  417.             4) DEBUG=4;;
  418.             *)
  419.                boolean_usage "-D" $1
  420.          esac
  421.          ;;
  422.       -A|--arch|--pkgarch)
  423.          shift
  424.          ARCHITECTURE=`eval echo $1`
  425.          ;;
  426.       --umask)
  427.          shift
  428.          CKUMASK=`eval echo $1`
  429.          ;;
  430.       --pkgname)
  431.          shift
  432.          NAME=`eval echo $1`
  433.          ;;
  434.       --pkgversion)
  435.          shift
  436.          VERSION=`eval echo $1`
  437.          ;;
  438.       --pkgrelease)
  439.          shift
  440.          RELEASE=`eval echo $1`
  441.          ;;
  442.       --pkglicense)
  443.          shift
  444.          LICENSE=`eval echo $1`
  445.          ;;
  446.       --pkggroup)
  447.          shift
  448.      # note: we use PKG_GROUP instead of GROUP since (t)csh sets GROUP.
  449.          PKG_GROUP=`eval echo $1`
  450.          ;;
  451.       --pkgsource)
  452.          shift
  453.          SOURCE=`eval echo $1`
  454.          ;;
  455.       --pkgaltsource)
  456.          shift
  457.          ALTSOURCE=`eval echo $1`
  458.          ;;
  459.       --pakdir)
  460.          shift
  461.          PAK_DIR=`eval echo $1`
  462.          ;;
  463.       --with-tar)
  464.          shift
  465.          TAR=`eval echo $1`
  466.          ;;
  467.       --docdir)
  468.          shift
  469.          DOC_DIR=`eval echo $1`
  470.          ;;
  471.       --provides)
  472.          shift
  473.          PROVIDES=`eval echo $1`
  474.          ;;
  475.       --requires)
  476.          shift
  477.          REQUIRES=`eval echo $1`
  478.          ;;
  479.       --maintainer)
  480.          shift
  481.          MAINTAINER=`eval echo $1`
  482.          ;;
  483.       --dpkgflags)
  484.          shift
  485.          DPKG_FLAGS=`eval echo $1`
  486.          ;;
  487.       --rpmflags)
  488.          shift
  489.          RPM_FLAGS=`eval echo $1`
  490.          ;;
  491.       -t|--type)
  492.          shift
  493.          INSTYPE=`echo $1 | tr 'a-z' 'A-Z'`
  494.          case `eval echo $INSTYPE` in
  495.             RPM|R)
  496.                INSTYPE=R;;
  497.             SLACKWARE|S)
  498.                INSTYPE=S;;
  499.             DEBIAN|D)
  500.                INSTYPE=D;;
  501.             *)
  502.                echo
  503.                echo $1 is not a valid packaging system. Please use \'rpm\', \'slackware\' or \'debian\'
  504.                echo 
  505.                echo
  506.                exit 1
  507.           esac
  508.           ;;
  509.        -R)
  510.           INSTYPE=R
  511.           CK_REDHAT=1
  512.           ;;
  513.        -S)
  514.           INSTYPE=S
  515.           CK_SLACKWARE=1
  516.           ;;
  517.        -D)
  518.           INSTYPE=D
  519.           CK_DEBIAN=1
  520.           ;;
  521.        --install)
  522.           shift
  523.           case `eval echo $1` in
  524.              1|yes|'')
  525.                 INSTALL=1;;
  526.              0|no)
  527.                 INSTALL=0;;
  528.              *)
  529.                 boolean_usage "--install" $1
  530.           esac
  531.           ;;
  532.        --si)
  533.           SHOW_INSTALL=1;;
  534.        --showinstall)
  535.           shift
  536.           case `eval echo $1` in
  537.              1|yes|'')
  538.                 SHOW_INSTALL=1;;
  539.              0|no)
  540.                 SHOW_INSTALL=0;;
  541.              *)
  542.                 boolean_usage "--showinstall" $1
  543.           esac
  544.           ;;
  545.        --ss)
  546.           SHOW_SLACK_INSTALL=1;;
  547.        --showslack)
  548.           shift
  549.           case `eval echo $1` in
  550.              1|yes|'')
  551.                 SHOW_SLACK_INSTALL=1;;
  552.              0|no)
  553.                 SHOW_SLACK_INSTALL=0;;
  554.              *)
  555.                 boolean_usage "--showslack" $1
  556.           esac
  557.           ;;
  558.        --deldoc)
  559.           shift
  560.           case `eval echo $1` in
  561.              1|yes|'')
  562.                 DEL_DOCPAK=1;;
  563.              0|no)
  564.                 DEL_DOCPAK=0;;
  565.              *)
  566.                 boolean_usage "--deldoc" $1
  567.           esac
  568.           ;;
  569.        --delspec)
  570.           shift
  571.           case `eval echo $1` in
  572.              1|yes|'')
  573.                 DEL_SPEC=1;;
  574.              0|no)
  575.                 DEL_SPEC=0;;
  576.              *)
  577.                 boolean_usage "--delspec" $1
  578.           esac
  579.           ;;
  580.        --deldesc)
  581.           shift
  582.           case `eval echo $1` in
  583.              1|yes|'')
  584.                 DEL_DESC=1;;
  585.              0|no)
  586.                 DEL_DESC=0;;
  587.              *)
  588.                 boolean_usage "--deldesc" $1
  589.           esac
  590.           ;;
  591.        --strip)
  592.           shift
  593.           case `eval echo $1` in
  594.              1|yes|'')
  595.                 STRIP_ELF=1;;
  596.              0|no)
  597.                 STRIP_ELF=0;;
  598.              *)
  599.                 boolean_usage "--strip" $1
  600.           esac
  601.           ;;
  602.  
  603.        --addso)
  604.           shift
  605.           case `eval echo $1` in
  606.              1|yes|'')
  607.                 ADD_SO=1;;
  608.              0|no)
  609.                 ADD_SO=0;;
  610.              *)
  611.                 boolean_usage "--strip" $1
  612.           esac
  613.           ;;
  614.  
  615.  
  616.        --stripso)
  617.           shift
  618.           case `eval echo $1` in
  619.              1|yes|'')
  620.                 STRIP_SO_ELF=1
  621.                 ;;
  622.              0|no)
  623.                 STRIP_SO_ELF=0;;
  624.              *)
  625.                 boolean_usage "--stripso" $1
  626.              esac
  627.           ;;
  628.        --gzman)
  629.           shift
  630.           case `eval echo $1` in
  631.              1|yes|'')
  632.                 COMPRESS_MAN=1;;
  633.              0|no)
  634.                 COMPRESS_MAN=0;;
  635.              *)
  636.                 boolean_usage "--gzman" $1
  637.           esac
  638.           ;;
  639.        --bk)
  640.           BACKUP=1;;
  641.        --backup)
  642.           shift
  643.           case `eval echo $1` in
  644.              1|yes|'')
  645.                 BACKUP=1;;
  646.              0|no)
  647.                 BACKUP=0;;
  648.              *)
  649.                 boolean_usage "--backup" $1
  650.           esac
  651.           ;;
  652.        --default)
  653.           ACCEPT_DEFAULT=1;;
  654.        -y)
  655.           ACCEPT_DEFAULT=1;;
  656.        --nodoc)
  657.           NODOC=1;;
  658.        --rpmi)
  659.           RPM_IU=i;;
  660.        --rpmu)
  661.           RPM_IU=U;;
  662.        --newslack)
  663.           NEW_SLACK=1;;
  664.        --inspect)
  665.           CK_INSPECT=1;;
  666.        --review-spec)
  667.           REVIEW_SPEC=1;;
  668.        --review-control)
  669.           REVIEW_CONTROL=1;;
  670.        --spec)
  671.       shift
  672.       SPEC_PATH=`eval echo $1`
  673.           if ! [ -f "$SPEC_PATH" ]; then
  674.              echog "Warning: .spec file path \"%s\" not found.\nWarning: Defaulting to \"%s\"." "$SPEC_PATH" "${PKG_BASENAME}.spec"
  675.           fi
  676.           ;;
  677.        --copyright|--version)
  678.           cat << EOF
  679.  
  680. Copyright (C) 2002 Felipe Eduardo Sanchez Diaz Duran <izto@asic-linux.com.mx>
  681.  
  682.     This program is free software; you can redistribute it and/or modify
  683.     it under the terms of the GNU General Public License as published by
  684.     the Free Software Foundation; either version 2 of the License, or
  685.     (at your option) any later version.
  686.  
  687.     This program is distributed in the hope that it will be useful,
  688.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  689.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  690.     GNU General Public License for more details.
  691.  
  692.     You should have received a copy of the GNU General Public License
  693.     along with this program; if not, write to the Free Software
  694.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  695.  
  696. EOF
  697.          exit 0;;
  698.        --autodoinst)
  699.           shift
  700.           case `eval echo $1` in
  701.              1|yes|'')
  702.                 AUTODOINST=1;;
  703.              0|no)
  704.                 AUTODOINST=0;;
  705.              *)
  706.                 boolean_usage "--autodoinst" $1
  707.           esac
  708.           ;;
  709.        --reset-uids)
  710.           shift
  711.           case `eval echo $1` in
  712.              1|yes|'')
  713.                 RESET_UIDS=1;;
  714.              0|no)
  715.                 RESET_UIDS=0;;
  716.              *)
  717.                 boolean_usage "--reset-uids" $1
  718.           esac
  719.           ;;
  720.         --fstrans)
  721.           shift
  722.           case `eval echo $1` in
  723.              1|yes|'')
  724.                 TRANSLATE=1;;
  725.              0|no)
  726.                 TRANSLATE=0;;
  727.              *)
  728.                 boolean_usage "--fstrans" $1
  729.           esac
  730.           ;;
  731.       --exclude)
  732.          shift
  733.          EXCLUDE=`eval echo $1`
  734.          ;;
  735.       --include)
  736.          shift
  737.          CK_INCLUDE_FILE=`eval echo $1`
  738.          ;;
  739.    esac
  740.    shift
  741. done
  742.  
  743. # See if we have and install command
  744. shift
  745.  
  746. [ "$1" = "" ] && set -- "make install"
  747.  
  748. # End of argument parsing
  749.  
  750. #############################################################################
  751.                    # We initialize some useful variables #
  752.                    #######################################
  753.  
  754. ################################################################
  755. # User-configurable variables were moved to the checkinstallrc #
  756. # file which is probably found at /etc/checkinstall            #          
  757. #                                                              #
  758. #                  DO NOT modify them here!!                   #
  759. ################################################################
  760.  
  761.  
  762. # Debug level
  763. ! [ "$DEBUG" ] && DEBUG=0
  764.  
  765. ! [ "$INSTALLWATCH_PREFIX" ] && INSTALLWATCH_PREFIX="/usr"
  766. ! [ "$INSTALLWATCH" ] && INSTALLWATCH=${INSTALLWATCH_PREFIX}/bin/installwatch
  767.  
  768. # Which makepkg to use
  769. ! [ "$MAKEPKG" ] && MAKEPKG=/sbin/makepkg
  770.  
  771. # Default MAKEPKG flags
  772. ! [ "$MAKEPKG_FLAGS" ] && MAKEPKG_FLAGS="-l y -c n"
  773.  
  774. # Default architecture type
  775. ! [ "$ARCHITECTURE" ] && ARCHITECTURE=""
  776.  
  777. # Default package type
  778. ! [ "$INSTYPE" ] && INSTYPE=""
  779.  
  780. # Interactively show the results of the install command
  781. # This is useful for interactive installation commands
  782. ! [ "$SHOW_INSTALL" ] && SHOW_INSTALL=1
  783.  
  784. # Show Slackware package installation script while it runs? Again, useful if
  785. # it's an interactive script
  786. ! [ "$SHOW_SLACK_INSTALL" ] && SHOW_SLACK_INSTALL=0
  787.  
  788. # Automatic deletion of "doc-pak" upon termination
  789. ! [ "$DEL_DOCPAK" ] && DEL_DOCPAK=1
  790.  
  791. # Automatic deletion of the spec file
  792. ! [ "$DEL_SPEC" ] && DEL_SPEC=1
  793.  
  794. # Automatic deletion of "description-pak" 
  795. ! [ "$DEL_DESC" ] && DEL_DESC=1
  796.  
  797.  
  798. # Automatically strip all ELF binaries
  799. ! [ "$STRIP_ELF" ] && STRIP_ELF=1
  800.  
  801. # Don't automatically strip all ELF binaries
  802. ! [ "$STRIP_SO_ELF" ] && STRIP_SO_ELF=0
  803.  
  804. # Don't automatically search shared libraries
  805. # nor add them to /etc/ld.so.conf
  806. ! [ "$ADD_SO" ] && ADD_SO=0
  807.  
  808. # Automatically compress all man pages
  809. ! [ "$COMPRESS_MAN" ] && COMPRESS_MAN=1
  810.  
  811. # Backup all files modified by the install command supplied by the user
  812. ! [ "$BACKUP" ] && BACKUP=1 
  813.  
  814. # Write description installing code to doinst.sh
  815. ! [ "$AUTODOINST" ] && AUTODOINST=1 
  816.  
  817. # Are we going to use filesystem translation?
  818. ! [ "$TRANSLATE" ] && TRANSLATE=1
  819.  
  820. # Reset the owner/group of all files to root.root?
  821. ! [ "$RESET_UIDS" ] && RESET_UIDS=0
  822.  
  823. # We won't include anything under this directories
  824. ! [ "$EXCLUDE" ] && EXCLUDE=""
  825.  
  826. # We will include anything listed in this file
  827. ! [ "$CK_INCLUDE_FILE" ] && CK_INCLUDE_FILE=""
  828.  
  829. # Accept the default answer for all the questions
  830. ! [ "$ACCEPT_DEFAULT" ] && ACCEPT_DEFAULT=0
  831.  
  832. # Use the default doc directory of /usr/doc
  833. ! [ "$DOC_DIR" ] && DOC_DIR=/usr/doc
  834.  
  835. # Do not include common documentation
  836. ! [ "$NODOC" ] && NODOC=0
  837.  
  838. # Use "-U" flag in rpm by default when installing a rpm package
  839. # This tells rpm to (U)pdate the package instead of (i)nstalling it.
  840. ! [ "$RPM_IU" ] && RPM_IU=U
  841.  
  842. # Use the new (8.1+) Slackware description format
  843. ! [ "$NEW_SLACK" ] && NEW_SLACK=1
  844.  
  845. # Inspect the file list before creating the package
  846. ! [ "$CK_INSPECT" ] && CK_INSPECT=0
  847.  
  848. # Review the .spec file before creating a .rpm
  849. ! [ "$REVIEW_SPEC" ] && REVIEW_SPEC=0
  850.  
  851. # Review the control file before creating a .deb
  852. ! [ "$REVIEW_CONTROL" ] && REVIEW_CONTROL=0
  853.  
  854. # Set the umask
  855. ! [ "$CKUMASK" ] && CKUMASK=0022
  856.  
  857. # No real installation if not explicitly asked
  858. ! [ "$INSTALL" ] && INSTALL=0
  859.  
  860. # The place where we will be storing the temp files
  861. ! [ "$BASE_TMP_DIR" ] && BASE_TMP_DIR=/var/tmp
  862.  
  863. # Default RPM FLAGS
  864. ! [ "$RPM_FLAGS" ] && RPM_FLAGS=" --force --nodeps --replacepkgs "
  865.  
  866. # Default DPKG FLAGS
  867. ! [ "$DPKG_FLAGS" ] && DPKG_FLAGS=""
  868.  
  869. # Default MAKEPKG FLAGS
  870. ! [ "$MAKEPKG_FLAGS" ] && MAKEPKG_FLAGS=""
  871.  
  872. # Show the makepkg program's output?
  873. ! [ "SHOW_MAKEPKG" ] && SHOW_MAKEPKG=0
  874.  
  875. ####################
  876. # Non-configurable #
  877. ####################
  878.  
  879. # Existing configuration files are always preserved
  880. [ -f description-pak ] && DEL_DESC=0
  881. [ -f SPEC_PATH ] && DEL_SPEC=0
  882. [ -d doc-pak ] && DEL_DOCPAK=0
  883.  
  884.  
  885.  
  886. INSTALLCMD="$@"
  887. : ${INSTALLCMD:='make install'}
  888.  
  889. # The editor we use to review the file list and .spec or control file
  890. if ! [ -x "$VISUAL" ]; then
  891.    if [ -x "$EDITOR" ]; then
  892.       VISUAL=$EDITOR
  893.    else
  894.       VISUAL=`which vi`
  895.    fi
  896. fi
  897.  
  898. # pkgtools in Slackware 8.1+ don't like the default tar binary and instead
  899. # use "tar-1.13". We'll use that too if we can find it.
  900.  
  901. BADTAR=0
  902.  
  903. if [ "$TAR" ]; then
  904.    ! [ -x "$TAR" ] && BADTAR=1 
  905. else
  906.    TAR=`which tar-1.13 2> /dev/null`
  907. fi
  908.  
  909. if ! [ -x "$TAR" ]; then
  910.    TAR="tar"
  911. fi
  912.  
  913. # If the user gave us a bad path to tar then we should warn him/her about it
  914. if [ $BADTAR -gt 0 ]; then
  915.    echo
  916.    echog "Warning: The path to tar specified in the command line is invalid.\nWarning: It has been set to %s" "$TAR"
  917.    echo
  918. fi
  919.  
  920. [ $DEBUG -gt 0 ] && echo "debug: TAR=$TAR"
  921. [ $DEBUG -gt 0 ] && echo "debug: VISUAL=$VISUAL"
  922.  
  923.                       #################################
  924.                       # Variable definition ends here #
  925. #############################################################################
  926.  
  927.  
  928.  
  929. if [ ! -x $INSTALLWATCH ]; then
  930.    echo
  931.    echog "I can't find $INSTALLWATCH."
  932.    echo
  933.    echog "I can't continue. Either install installwatch or\nmodify the INSTALLWATCH variable in this script,\nthen run checkinstall again."
  934.    echo
  935.    exit 1
  936. fi
  937.  
  938. echo
  939.  
  940. # Set the umask. If not specified with "--umask" then we'll use 0022, a 
  941. # standard, non-paranoid reasonable value.
  942.  
  943. if [ $DEBUG -gt 0 ] ;then 
  944.    echo "debug: Setting umask => $CKUMASK"
  945. fi
  946. umask $CKUMASK
  947.  
  948.  
  949. # Find a safe TMP_DIR
  950.  
  951. TMP_DIR=${BASE_TMP_DIR}/`awk 'BEGIN { srand(); for (i=1;i<21;i++) { a=95; while (a > 90 && a < 97) { a=65+int(50*rand())}; printf("%c", a) } }'`
  952. [ -e "$TMP_DIR" ] && rm -rf $TMP_DIR
  953. if [ -e "$TMP_DIR" ]; then 
  954.    echo
  955.    echog "My temp dir exists already.\nThis looks like a symlink attack!"
  956.    echo 
  957.    echog "*** Aborting"
  958.    echo
  959.    exit 1
  960. fi
  961.  
  962. if [ "$TMP_DIR" = "$BASE_TMP_DIR" -o "$TMP_DIR" = "/" ]; then
  963.   echo 
  964.   echog "%s is an unacceptable value for the temp dir. Please \nedit the variable definition for %s and try again." "$TMP_DIR" "$TMP_DIR"
  965.   echo
  966.   echog "*** Aborting"
  967.   echo
  968.   exit 1
  969. fi
  970.  
  971.  
  972. mkdir $TMP_DIR
  973. chmod 700 $TMP_DIR
  974. RETURN=$?
  975.  
  976. if [ $RETURN -gt 0 ]; then
  977.    echo
  978.    echog "**** Failed to create temp dir! \n**** Do you have write permission for %s? \n\n**** Aborting installation." "$BASE_TMP_DIR"
  979.    echo
  980.    exit  $RETURN
  981. fi
  982.  
  983. BUILD_DIR=${TMP_DIR}/package
  984. mkdir $BUILD_DIR
  985.  
  986. if [ $DEBUG -gt 0 ] ;then 
  987.    echo "debug: The temporary directory is: [ $TMP_DIR ]"
  988.    echo
  989. fi
  990.  
  991.  
  992. # 001117-BaP: We can create a default set of docs on the fly . . .
  993. #   The list I've included should cover most packages adequately. If not,
  994. #   then you should really create the package doc set *manually*
  995.  
  996.  
  997. # Check if --nodoc was specified
  998. if [ "$NODOC" = "0" ]; then 
  999.  
  1000. if  ! [ -d "$DIRECTORIO_FUENTE/doc-pak" ]; then
  1001.     echogn "The package documentation directory ./doc-pak does not exist. \nShould I create a default set of package docs? "
  1002.     if  yorn ; then
  1003.         echo
  1004.         echogn "Preparing package documentation..."
  1005.         mkdir doc-pak
  1006.          for f in ABOUT ABOUT-NLS ANNOUNCE AUTHORS *BUGS* CHANGES CONFIGURATION *COPYING* *COPYRIGHT* CREDITS ChangeLog Changelog CHANGELOG CONTRIBUTORS *FAQ* FEATURES FILES HACKING History HISTORY INSTALL* LICENSE LSM MANIFEST NEWS *README* *Readme* SITES *RELEASE* RELNOTES THANKS TIPS TODO VERSION CONFIGURATION* GPL License  Doc doc Docs* docs* Roadmap ROADMAP; do
  1007.             if [ -e $f ]; then
  1008.                if ! [ -L $f ]; then
  1009.                   cp -a $f doc-pak
  1010.                else
  1011.                   cp -LpR $f doc-pak
  1012.                fi
  1013.  
  1014.             fi
  1015.         done
  1016.         okfail
  1017.         DOCS=`ls doc-pak`
  1018.         if ! [ "$DOCS" ]; then
  1019.            echo
  1020.            echog "*** No known documentation files were found. The new package \n*** won\'t include a documentation directory."
  1021.            rm -rf doc-pak                 # If doc-pak is empty then we
  1022.         fi                                # don't need it
  1023.     fi                                    
  1024.     
  1025. fi
  1026.  
  1027. fi # End of NODOC
  1028.  
  1029. ##############################################################################
  1030. #
  1031. # Find out the packaging method to use
  1032. #
  1033.  
  1034.  
  1035. while ! [ "$INSTYPE" ]; do
  1036.  
  1037.    echo
  1038.    echog "Please choose the packaging method you want to use."
  1039.    echogn "Slackware [S], RPM [R] or Debian [D]? "
  1040.    read INSTYPE
  1041.  
  1042. echo
  1043.  
  1044.        case $INSTYPE in
  1045.          S|s) 
  1046.             INSTYPE=S
  1047.             CK_SLACKWARE=1
  1048.             ;;
  1049.          R|r)
  1050.             INSTYPE=R
  1051.             CK_REDHAT=1
  1052.             ;;
  1053.          D|d)
  1054.             INSTYPE=D
  1055.             CK_DEBIAN=1
  1056.             ;;
  1057.          *)
  1058.            echo
  1059.            echog '*** Invalid type.'
  1060.            echo
  1061.            INSTYPE=""
  1062.            ;;
  1063.        esac
  1064. done
  1065.  
  1066. ## Do we have a package description file? If we don't then 
  1067. ## we should write one
  1068.  
  1069. cd "$DIRECTORIO_FUENTE"
  1070.  
  1071. # If we already have a slack-desc we use it unless
  1072. # we have a description-pak too
  1073.  
  1074. if [ -r slack-desc -a ! -r description-pak ]; then
  1075.    cat -s slack-desc | grep -v \#  | grep -v \| | cut -d : -f 2 | sed '/./,/^$/!d' > description-pak
  1076. fi
  1077.  
  1078.  
  1079. if [ $ACCEPT_DEFAULT -eq 0 ]; then  # If --default is given, we skip this 
  1080.  if ! [ -r description-pak ]; then
  1081.    DESCRIPTION="Package created with checkinstall $CHECKINSTALL_VERSION"
  1082.    echo
  1083.    echogn "Please write a description for the package."
  1084.  
  1085.    # If we selected Slackware, then give the pkgtool warning
  1086.  
  1087.    if [ "$CK_SLACKWARE" ]; then 
  1088.       echog " Remember that pkgtool shows\nonly the first one when listing packages so make that one descriptive."
  1089.    fi
  1090.    echo
  1091.    echog "End your description with an empty line or EOF."
  1092.    while [ "$DESCRIPTION" ]; do
  1093.       echo -n ">> " 
  1094.       read DESCRIPTION
  1095.       [ "$DESCRIPTION" ] && echo "$DESCRIPTION" >> description-pak
  1096.    done
  1097.  fi
  1098. fi
  1099.  
  1100. # We still don't have it??
  1101. ! [ -r description-pak ] && echo "Package created with checkinstall $CHECKINSTALL_VERSION" > description-pak
  1102.  
  1103. # Warn the user if we're using the new Slackware description format
  1104. # and the description is bigger than 11 lines
  1105.  
  1106. if [ $NEW_SLACK -gt 0 ]; then
  1107.    if [ `wc -l < description-pak` -gt 11 ]; then
  1108.       echo
  1109.       echog "Warning: Your package description is bigger than 11 lines.\nWarning: The Slackware 8.1+ pkgtools might not like it."
  1110.       echo
  1111.    fi
  1112. fi
  1113.  
  1114.  
  1115. INSTYPE=`echo $INSTYPE | tr a-z A-Z`
  1116.  
  1117. case $INSTYPE in
  1118.    S|s) 
  1119.       CK_SLACKWARE=1
  1120.       echo
  1121.       echog "********************************************\n**** Slackware package creation selected ***\n********************************************"
  1122.    ;;
  1123.    R|r)
  1124.       CK_REDHAT=1
  1125.       echo
  1126.       echog "**************************************\n**** RPM package creation selected ***\n**************************************"
  1127.    ;;
  1128.    D|d)
  1129.       CK_DEBIAN=1
  1130.       echo
  1131.       echog "*****************************************\n**** Debian package creation selected ***\n*****************************************"
  1132. esac
  1133.  
  1134. ########## Acquire some info about the package ##########
  1135.  
  1136.  
  1137. # Figure out what kind of machine are we running on
  1138.  
  1139. if ! [ "$ARCHITECTURE" ]; then
  1140.    ARCHITECTURE=`uname -m`
  1141.    echo $ARCHITECTURE | grep -e "i[3456]86" &> /dev/null
  1142.    [ $? -eq 0 ] && ARCHITECTURE=i386  # Arch will be "i386" for any of
  1143. fi                                    # i386, i486, i586 or i686.
  1144.                                       # You can change this with "--arch"
  1145.  
  1146.    # Fix the PowerPC architecture description if we're on Debian
  1147.    
  1148.    if [ "$CK_DEBIAN" = "1" ] && [ "$ARCHITECTURE" = "ppc" ]; then
  1149.       ARCHITECTURE="powerpc"
  1150.    fi
  1151.  
  1152. if [ -f "$SPEC_PATH" ]; then 
  1153.    SUMMARY=`getparameter "^[Ss]ummary"`
  1154.    NAME=`getparameter "^[Nn]ame"`
  1155.    VERSION=`getparameter "^[Vv]ersion"`
  1156.    RELEASE=`getparameter "^[Rr]elease"`
  1157.    LICENSE=`getparameter "^[Cc]opyright"`
  1158.    PKG_GROUP=`getparameter "^[Gg]roup"`
  1159.    PROVIDES=`getparameter "^[Pp]rovides"`
  1160.    REQUIRES=`getparameter "^[Rr]equires"`
  1161. fi
  1162.       
  1163.    OPTION=junk
  1164.    while [ "$OPTION" ]; do
  1165.  
  1166.       # Some sanity checks
  1167.       ! [ "$SUMMARY" ] && SUMMARY=`head -1 description-pak`
  1168.       ! [ "$NAME" ] && NAME=`echo "$PKG_BASENAME" | rev | cut -f2- -d"-" | rev`
  1169.  
  1170.       if [ "$CK_DEBIAN" ]; then       # Convert name to lower case
  1171.       echo $NAME | grep -e "[A-Z]" &> /dev/null
  1172.          if [ $? -eq 0 ]; then
  1173.             echo
  1174.             echog "*** Warning: The package name \"%s\" contains upper case\n*** Warning: letters. dpkg might not like that so I changed\n*** Warning: them to lower case." "$NAME"
  1175.             NAME=`echo $NAME | tr 'A-Z' 'a-z'`
  1176.  
  1177.  
  1178.          fi
  1179.       fi
  1180.  
  1181.  
  1182.       ! [ "$VERSION" ] && VERSION=`echo "$PKG_BASENAME" | rev | cut -f1 -d"-" | rev`
  1183.  
  1184.       ## Did we get a usable version?
  1185.  
  1186.       if [  "$VERSION" = "$PKG_BASENAME" ]; then
  1187.  
  1188.          # If we did not then try getting it from the config.log file
  1189.          if [ -f "$DIRECTORIO_FUENTE/config.log" ]; then
  1190.             VERSION=`grep '#define VERSION' config.log| awk -F \" '{print $ 2}'`
  1191.  
  1192.          else
  1193.  
  1194.             # We use the current that if everything else fails
  1195.             VERSION=`date +%Y%m%d` 
  1196.          fi
  1197.       fi
  1198.  
  1199.  
  1200.  
  1201.       if [ "$CK_DEBIAN" ]; then       # Check for a valid version for dpkg
  1202.          echo $VERSION | grep -e "[0-9]" &> /dev/null
  1203.          if [ $? -gt 0 ]; then
  1204.             echo
  1205.             echog "*** Warning: The package version \"%s\" does not\n*** Warning: contain any digits. dpkg might not like that." "$VERSION"
  1206.          fi
  1207.       fi
  1208.  
  1209.  
  1210.  
  1211.       if [ ! "$PAGER" ]; then         # no default pager defined
  1212.          if [ "$CK_DEBIAN" ]; then    # use Debian's pager if on Debian
  1213.             PAGER=/usr/bin/sensible-pager
  1214.          else
  1215.             PAGER=less             # use less otherwise
  1216.          fi
  1217.       fi
  1218.  
  1219.  
  1220.  
  1221.       ! [ "$RELEASE" ] && RELEASE="1"
  1222.       ! [ "$LICENSE" ] && LICENSE="GPL"
  1223.       ! [ "$PKG_GROUP" ] && [ "$CK_REDHAT" ] && PKG_GROUP="Applications/System"
  1224.       ! [ "$PKG_GROUP" ] && [ "$CK_DEBIAN" ] && PKG_GROUP="checkinstall"
  1225.       ! [ "$PKG_GROUP" ] && [ "$CK_SLACKWARE" ] && PKG_GROUP="Applications/System"
  1226.  
  1227.       ! [ "$ARCHITECTURE" ] && ARCHITECTURE="i386"
  1228.       ! [ "$SOURCE" ] && SOURCE="$PKG_BASENAME"
  1229.       ! [ "$ALTSOURCE" ] && ALTSOURCE=""
  1230.       ! [ "$PROVIDES" ] && PROVIDES="$NAME"
  1231.       ! [ "$REQUIRES" ] && REQUIRES=""
  1232.       # bond: added this so it is easy to change the Maintainer: field
  1233.       # just by setting the MAINTAINER environment variable
  1234.  
  1235.       # Try to find the hostname in the environment
  1236.       if [ "$HOSTNAME" ]; then 
  1237.          MAINTDOMAIN=$HOSTNAME
  1238.       else
  1239.          hostname -f &> /dev/null
  1240.          if [ $? -gt 0]; then
  1241.             MAINTDOMAIN="localhost"
  1242.          else
  1243.             MAINTDOMAIN=`hostname -f`
  1244.          fi
  1245.       fi
  1246.       ! [ "$MAINTAINER" ] && MAINTAINER=${LOGNAME:-root}@${MAINTDOMAIN}
  1247.       
  1248.  
  1249.       echo
  1250.       echog "This package will be built according to these values: "
  1251.       echo
  1252.       # Debian maintainers use the Maintainer: field and want to be able
  1253.       # to change it. If we are not on debian we don't need the field...
  1254.       [ "$CK_DEBIAN" ] && echog "0 -  Maintainer: [ %s ]" "$MAINTAINER"
  1255.  
  1256.       echog "1 -  Summary: [ %s ]" "$SUMMARY"
  1257.       echog "2 -  Name:    [ %s ]" "$NAME"
  1258.       echog "3 -  Version: [ %s ]" "$VERSION"
  1259.       echog "4 -  Release: [ %s ]" "$RELEASE"
  1260.       echog "5 -  License: [ %s ]" "$LICENSE"
  1261.       echog "6 -  Group:   [ %s ]" "$PKG_GROUP"
  1262.       echog "7 -  Architecture: [ %s ]" "$ARCHITECTURE"
  1263.       echog "8 -  Source location: [ %s ]" "$SOURCE"
  1264.       echog "9 -  Alternate source location: [ %s ]" "$ALTSOURCE"
  1265.       echog "10 - Requires: [ %s ]" "$REQUIRES"
  1266.       [ "$CK_REDHAT" ] && echog "11 - Provides: [ %s ]" "$PROVIDES"
  1267.  
  1268.  
  1269.       echo
  1270.       echogn "Enter a number to change any of them or press ENTER to continue: "
  1271.       if [ $ACCEPT_DEFAULT -eq 1 ]; then
  1272.          echo
  1273.          OPTION=""
  1274.       else
  1275.          read OPTION
  1276.       fi
  1277.  
  1278.       case $OPTION in
  1279.          1)
  1280.             echog "Enter new summary: "
  1281.             echo -n ">> "
  1282.             read SUMMARY
  1283.             ;;
  1284.          2)
  1285.             echog "Enter new name: "
  1286.             echo -n ">> "
  1287.             read NAME
  1288.             ;;
  1289.          3)
  1290.             echog "Enter new version: "
  1291.             echo -n ">> "
  1292.             read VERSION
  1293.             ;;
  1294.          4)
  1295.             echog "Enter new release number: "
  1296.             echo -n ">> "
  1297.             read RELEASE
  1298.             ;;
  1299.          5)
  1300.             echog "Enter the license type: "
  1301.             echo -n ">> "
  1302.             read LICENSE
  1303.             ;;
  1304.          6)
  1305.             echog "Enter the new software group: "
  1306.             echo -n ">> "
  1307.             read PKG_GROUP
  1308.             ;;
  1309.          7)
  1310.             echog "Enter the architecture type: "
  1311.             echo -n ">> "
  1312.             read ARCHITECTURE
  1313.             ;;
  1314.          8)
  1315.             echog "Enter the source location: "
  1316.             echo -n ">> "
  1317.             read SOURCE
  1318.             ;;
  1319.          9)
  1320.             echog "Enter the alternate source location: "
  1321.             echo -n ">> "
  1322.             read ALTSOURCE
  1323.             ;;
  1324.          0) # bond: again, debian-specific
  1325.         [ "$CK_DEBIAN" ] && {
  1326.             echog "Enter the maintaner's name and e-mail address: "
  1327.             echo -n ">> "
  1328.             read MAINTAINER
  1329.         }
  1330.             ;;
  1331.          10)
  1332.             # 01-12-06 UKo: new feature
  1333.             echog "Enter the provided features: "
  1334.             echo -n ">> "
  1335.             read PROVIDES
  1336.             ;;
  1337.          11)
  1338.             [ "$CK_REDHAT" ] && {
  1339.             echog "Enter the additional requirements: "
  1340.             echo -n ">> "
  1341.             read REQUIRES
  1342.             }
  1343.             ;;
  1344.       esac
  1345.    done
  1346.    
  1347.    # The PKG_BASENAME is adjusted to reflect any changes
  1348.    # in the NAME and VERSION of the package
  1349.    # NOTE: on debian we use NAME alone, instead - see below
  1350.  
  1351.    PKG_BASENAME="$NAME-$VERSION" 
  1352.  
  1353. ##############################################################################
  1354.  
  1355.  
  1356. #
  1357. # We run the program installation from the source directory       
  1358. #
  1359.  
  1360. # Write a small script to run the install command. This way the LD_PRELOAD
  1361. # environment variable will be available to it, wich among other things
  1362. # will allow proper detection of new symbolic links and files created by
  1363. # subshells.
  1364.  
  1365. [ $DEBUG -gt 0 ] && echo "debug: CK_INCLUDE_FILE = $CK_INCLUDE_FILE"
  1366.  
  1367. TMP_SCRIPT=${TMP_DIR}/installscript.sh
  1368.  
  1369. cat << EOF > $TMP_SCRIPT
  1370. #!/bin/sh
  1371.  
  1372. cd "$DIRECTORIO_FUENTE"
  1373. $INSTALLCMD
  1374.  
  1375. # Report success or failure
  1376. if [ \$? -eq 0 ]; then
  1377.    exit 0
  1378. else
  1379.    exit 1
  1380. fi
  1381.  
  1382. EOF
  1383.  
  1384. # No one needs to see what we are doing. It's safer this way.
  1385. chmod 700 $TMP_SCRIPT
  1386.  
  1387.  
  1388. echo
  1389. echogn "Installing with %s..." "$INSTALLCMD"
  1390.  
  1391.  
  1392. #
  1393. #   We exclude as many "dangerous" directories as possible from translation.
  1394. # installwatch excludes itself some directories, but we put them all here,
  1395. # to be explicit.
  1396. #
  1397. IEXCLUDE="${DIRECTORIO_FUENTE},/dev,/proc,/tmp,/var/tmp"
  1398.   
  1399.  
  1400. # Run the install command, showing the results interactively if we were asked
  1401. # to do so in the configuration section (see the SHOW_INSTALL switch above)
  1402. INSTALL_FAILED=0
  1403. if [ $SHOW_INSTALL -eq 0 ]; then
  1404.  
  1405.    $INSTALLWATCH --logfile=${TMP_DIR}/newfiles.tmp --exclude="${IEXCLUDE}" \
  1406.    --root=${TMP_DIR} --transl=${TRANSLATE} --backup=${BACKUP} --dbglvl=$DEBUG\
  1407.    $TMP_SCRIPT &> /${TMP_DIR}/install.log
  1408.  
  1409.    okfail
  1410.    INSTALL_FAILED=$?
  1411. else
  1412.    echo
  1413.    echo
  1414.    echog "========================= Installation results ==========================="
  1415.    $INSTALLWATCH --logfile=${TMP_DIR}/newfiles.tmp --exclude="${IEXCLUDE}" \
  1416.    --root=${TMP_DIR} --transl=${TRANSLATE} --backup=${BACKUP} --dbglvl=$DEBUG\
  1417.    $TMP_SCRIPT 2>&1
  1418.    if [ $? -eq 0 ]; then 
  1419.       echo
  1420.       echog "======================== Installation successful =========================="
  1421.    else        
  1422.       INSTALL_FAILED=1
  1423.    fi
  1424. fi
  1425.  
  1426. unset LD_PRELOAD
  1427.  
  1428.  
  1429. VIEWLOG="n"
  1430. if [ $INSTALL_FAILED -gt 0 ]; then 
  1431.    echo
  1432.    echog "****  Installation failed. Aborting package creation."
  1433.    VIEWLOG="y"
  1434. fi
  1435.  
  1436. if [ $SHOW_INSTALL -eq 0 ]; then
  1437.    echo
  1438.    echogn "Do you want to view the installation log file? "
  1439.  
  1440.    if  yorn $VIEWLOG ; then
  1441.  
  1442.       (echo
  1443.        echogn ' ***************************************************************\n         Installation results. You can find them in\n       %s\n ***************************************************************\n' "${TMP_DIR}/install.log"
  1444.        cat /${TMP_DIR}/install.log)  | $PAGER
  1445.    fi
  1446. fi
  1447.  
  1448. if [ $INSTALL_FAILED -gt 0 ]; then 
  1449.    cleanup
  1450.        exit $INSTALL_FAILED
  1451.     fi
  1452.  
  1453.     # If translation was active, the installed files are under /transl
  1454.     TRANSLROOT="/"
  1455.     if [ "${TRANSLATE}" = "1" ]; then
  1456.         TRANSLROOT="${TMP_DIR}/TRANSL"
  1457.     fi
  1458.  
  1459.  
  1460.     # Copy the documentation files           
  1461.  
  1462.  
  1463.     if [ -d "$DIRECTORIO_FUENTE/doc-pak" ]; then    # Are there any files? 
  1464.        echo
  1465.        echo "Copying documentation directory..."
  1466.        mkdir -p "${BUILD_DIR}/${DOC_DIR}/${PKG_BASENAME}"
  1467.        (cd $DIRECTORIO_FUENTE/doc-pak;$TAR -cpf - .) |
  1468.        (cd ${BUILD_DIR}/${DOC_DIR}/${PKG_BASENAME};$TAR -f - -xvp) 
  1469.        chown -R root.root "${BUILD_DIR}/${DOC_DIR}/${PKG_BASENAME}"
  1470.     fi
  1471.     
  1472.     # If we have a --include list file, copy the files listed there to /
  1473.     # If translation is on, it will catch these too.
  1474.     
  1475.     if [ -f "${DIRECTORIO_FUENTE}/${CK_INCLUDE_FILE}" ]; then
  1476.           cat "${DIRECTORIO_FUENTE}/${CK_INCLUDE_FILE}" | while read include_file; do
  1477.           $TAR -cpf - "$include_file" 2>/dev/null | $TAR -f - -xp -C $BUILD_DIR  &> /dev/null
  1478.        done
  1479.     fi
  1480.  
  1481.  
  1482.     #
  1483.     # Extract the relevant files from the modified files list
  1484.     #
  1485.  
  1486.     # Find regular files first
  1487.     [ $DEBUG -gt 0 ] && echo "debug: BASE_TMP_DIR: $BASE_TMP_DIR"
  1488.     cat /${TMP_DIR}/newfiles.tmp | egrep -v '^[-0-9][0-9]*[       ]*unlink' | cut -f 3 | egrep -v "^(/dev|$BASE_TMP_DIR|/tmp)" | sort -u > /${TMP_DIR}/newfiles
  1489.  
  1490.     # symlinks are next
  1491.     cat /${TMP_DIR}/newfiles.tmp | egrep -v '^[-0-9][0-9]*[       ]*unlink' | cut -f 4 | egrep -v "^(/dev|$BASE_TMP_DIR|/tmp)" | grep -v "#success" | sort -u  >> /${TMP_DIR}/newfiles
  1492.  
  1493.     # OK, now we clean it up a bit
  1494.     mv /${TMP_DIR}/newfiles.tmp /${TMP_DIR}/newfiles.installwatch
  1495.     sort -u <  /${TMP_DIR}/newfiles | uniq  | while read file; do
  1496.        if [ -e "${TRANSLROOT}${file}" ]; then
  1497.           echo $file >> /${TMP_DIR}/newfiles.tmp
  1498.        else
  1499.           FILE_SYM=`file "${TRANSLROOT}${file}" | grep 'symbolic link'`
  1500.           [ "${FILE_SYM}" != "" ] && echo $file >> /${TMP_DIR}/newfiles.tmp
  1501.        fi
  1502.     done
  1503.  
  1504.     cp /${TMP_DIR}/newfiles.tmp /${TMP_DIR}/newfiles
  1505.  
  1506.     # Don't include anything under the directories specified with "--exclude"
  1507.  
  1508.     [ $DEBUG -gt 0 ] && echo "debug: EXCLUDE=$EXCLUDE"
  1509.  
  1510.     for exclude in `echo $EXCLUDE | awk '{ split ($0, files,","); for(i=1; files[i] != ""; i++) print files[i];}'`; do
  1511.        if [ -d $exclude ]; then  # If it's a directory, ignore everything below it
  1512.           egrep -v "^$exclude" < /${TMP_DIR}/newfiles > /${TMP_DIR}/newfiles.tmp
  1513.        else
  1514.           if [ -f $exclude ]; then  # If it's a file, ignore just this one
  1515.          egrep -v "^$exclude$" < /${TMP_DIR}/newfiles > /${TMP_DIR}/newfiles.tmp
  1516.           fi
  1517.        fi
  1518.        cp /${TMP_DIR}/newfiles.tmp /${TMP_DIR}/newfiles
  1519.     done
  1520.  
  1521.  
  1522.     ## Find any files created in `pwd`. We probably don't want them here
  1523.  
  1524.     grep "^`pwd`" ${TMP_DIR}/newfiles > /${TMP_DIR}/unwanted 
  1525.     if [ $? = 0 ]; then 
  1526.        echo
  1527.        echog "Some of the files created by the installation are inside the build\ndirectory: %s" "`pwd`"
  1528.        echo
  1529.        echogn "You probably don't want them to be included in the package,\nespecially if they are inside your home directory.\nDo you want me to list them? "
  1530.        if  yorn "n"; then
  1531.           $PAGER ${TMP_DIR}/unwanted
  1532.        fi
  1533.        echogn "Should I exclude them from the package? (Saying yes is a good idea) "
  1534.        if  yorn ; then
  1535.           grep -v "`pwd`" ${TMP_DIR}/newfiles > /${TMP_DIR}/newfiles.tmp
  1536.           mv /${TMP_DIR}/newfiles.tmp /${TMP_DIR}/newfiles
  1537.        fi
  1538.     fi
  1539.  
  1540.     # If requested with "--inspect" we run an editor on the newfiles list
  1541.     if [ $CK_INSPECT -gt 0 ]; then
  1542.        echo
  1543.        echog "You requested to review the list of files that will be\nincluded in this package.\n\nNow you'll have the chance to review and optionally modify it."
  1544.        echo
  1545.        echog "Press ENTER to continue."
  1546.        read junk
  1547.        $VISUAL ${TMP_DIR}/newfiles
  1548.  
  1549.        # Check if new files were added by the user
  1550.        cat /${TMP_DIR}/newfiles | while read file; do 
  1551.           if ! [ -e "${TRANSLROOT}${file}" ]; then
  1552.          ($TAR -C / -cpf - ".${file}"| $TAR -f - -xvpC ${BUILD_DIR}) >> /${TMP_DIR}/updated-by-user.log 2>&1
  1553.           fi
  1554.        done
  1555.  
  1556.     fi
  1557.  
  1558.  
  1559.     # Copy the files to the temporary directory
  1560.     #
  1561.  
  1562.     echo
  1563.     echogn "Copying files to the temporary directory..."
  1564.  
  1565.     cd /
  1566.  
  1567.     ( cat /${TMP_DIR}/newfiles | while read i; do 
  1568.           if [ ! -d "${TRANSLROOT}${i}" -o -L "${TRANSLROOT}${i}" ]; then
  1569.           echo ".${i}"
  1570.        fi
  1571.     done ) > /${TMP_DIR}/newfiles-tar
  1572.  
  1573.     cat /${TMP_DIR}/newfiles-tar | while read file; do
  1574.        ($TAR -C "${TRANSLROOT}" -cpf - $file | $TAR -C ${BUILD_DIR} -xpf - ) >> /${TMP_DIR}/checkinstall.log 2>&1
  1575.     done
  1576.  
  1577.     okfail
  1578.  
  1579.     cd /
  1580.  
  1581.  
  1582.     # Reset all files' owner/group to root.root, and all dirs' perms to 755
  1583.     #
  1584.     # We do this if asked with "--reset-uids" in the command line, like the
  1585.     # similar option in Slackware's makepkg.
  1586.  
  1587.     if [ $RESET_UIDS -gt 0 ]; then
  1588.        find "$BUILD_DIR" -exec chown root.root {} \;
  1589.        find "$BUILD_DIR" -type d -exec chmod 755 {} \;
  1590.     fi
  1591.  
  1592.     ##############################################################################
  1593.                     # Strip ELF binaries # 
  1594.                     ######################
  1595.  
  1596.  
  1597.     #
  1598.     # Note: The code in this section was taken from the brp-strip script included 
  1599.     # in rpm-4.0.2, which is distributed under the GNU GPL. The copyright
  1600.     # for this code belongs to its owner. See the file COPYING for details.
  1601.     #
  1602.  
  1603.     if [ $STRIP_ELF -eq 1 ]; then
  1604.        echo
  1605.        if [ $STRIP_SO_ELF -eq 1 ]; then
  1606.            echogn "Striping ELF binaries and libraries..."
  1607.        else
  1608.            echogn "Striping ELF binaries..."
  1609.        fi
  1610.        for f in `find ${BUILD_DIR} -type f \( -perm -0100 -or -perm -0010 -or -perm -0001 \)` ; do
  1611.  
  1612.            if [ $STRIP_SO_ELF -eq "0" -a "`file $f | grep -v ' shared object,'`" = "" ]; then
  1613.            #if this is a *.so* file and we don't have to strip it, then filter 'em
  1614.            continue
  1615.            fi
  1616.            if [ "`file $f | sed -n -e 's/^\(.*\):[  ]*ELF.*, not stripped/\1/p'`" = "" ]; then
  1617.            continue
  1618.            fi
  1619.            strip -p $f || :
  1620.        done
  1621.        okfail
  1622.     fi
  1623.                      ###################
  1624.                      # End of striping #
  1625.     ##############################################################################
  1626.  
  1627.  
  1628.     ##############################################################################
  1629.                     # Compress man pages #
  1630.                     ######################
  1631.  
  1632. #
  1633. # Note: The code in this section is based on the brp-compress script
  1634. # included in rpm-4.0.2, which is distributed under the GNU GPL. The
  1635. # copyright for this code belongs to its owner. See the file COPYING for
  1636. # details.
  1637. #
  1638.  
  1639. if [ $COMPRESS_MAN -eq 1 ]; then
  1640.  echo
  1641.  echogn "Compressing man pages..."
  1642.  cd $BUILD_DIR
  1643.  
  1644.  # Compress man pages
  1645.  COMPRESS="gzip -9"
  1646.  COMPRESS_EXT=.gz
  1647.  
  1648.  for d in ./usr/local/man/man* ./usr/local/man/*/man* ./usr/local/info \
  1649.      ./usr/local/share/man/man* ./usr/local/share/man/*/man* \
  1650.      ./usr/local/share/info \
  1651.      ./usr/local/kerberos/man \
  1652.      ./usr/local/share/doc/*/man/man* ./usr/local/lib/*/man/man* \
  1653.      ././usr/man/man* ./usr/man/*/man* ./usr/info \
  1654.      ./usr/share/man/man* ./usr/share/man/*/man* ./usr/share/info \
  1655.      ./usr/kerberos/man ./usr/X11R6/man/man* ./usr/lib/perl5/man/man* \
  1656.      ./usr/share/doc/*/man/man* ./usr/lib/*/man/man*
  1657.  do
  1658.      [ -d $d ] || continue
  1659.      for f in `find $d -type f`
  1660.      do
  1661.         [ -f "$f" ] || continue
  1662.      [ "`basename $f`" = "dir" ] && continue
  1663.  
  1664.          # decompress manpage by "cat"ing it, this allows decompression of
  1665.          # hardlinked manpages and allows gunzip of a compressed page which is
  1666.          # actually called "man.1" and not "man.1.gz", something it won't do
  1667.          # when operating directly on file.
  1668.          # this overcomes installs that create (un)compressed pages with names
  1669.          # that don't correspond with the compression.
  1670.          # this is done to a temporary file so we can detect hardlinks to
  1671.          # original file.
  1672.        b=`echo $f | sed -e 's/\.Z$//;s/\.gz$//;s/\.bz2$//'`
  1673.          cp -p $f $b.tmp # setup up permissions on our new file
  1674.          cat $f | gunzip -c 2>/dev/null >$b.tmp || {
  1675.            cat $f | bunzip2 -c 2>/dev/null >$b.tmp || {
  1676.              cat $f >$b.tmp
  1677.            }
  1678.          }
  1679.  
  1680.        $COMPRESS $b.tmp
  1681.          # find any hard links to the old manpage and link to the new one..
  1682.          inode=`ls -i $f | awk '{ print $1 }'`
  1683.          others=`find $d -type f -inum $inode`
  1684.        if [ -n "$others" ]; then
  1685.          for afile in $others ; do
  1686.            [ "$afile" = "$f" ] && continue
  1687.              rm -f ${TRANSLROOT}/${afile} ${afile}
  1688.              afile=`echo $afile | sed -e 's/\.Z$//;s/\.gz$//;s/\.bz2$//'`
  1689.            ln $b.tmp$COMPRESS_EXT $afile$COMPRESS_EXT
  1690.          done
  1691.          fi
  1692.          rm -f ${TRANSLROOT}/${f} ${f}
  1693.          mv $b.tmp$COMPRESS_EXT $b$COMPRESS_EXT
  1694.     done
  1695.  
  1696.      for f in `find $d -type l`
  1697.      do
  1698.      l=`ls -l $f | awk '{ print $11 }' | sed -e 's/\.gz$//' -e 's/\.bz2$//' -e 's/\.Z$//'`
  1699.      rm -f ${TRANSLROOT}/${f}
  1700.      b=`echo $f | sed -e 's/\.gz$//' -e 's/\.bz2$//' -e 's/\.Z$//'`
  1701.      ln -sf $l$COMPRESS_EXT $b$COMPRESS_EXT
  1702.      done
  1703.  done
  1704.  okfail
  1705. fi
  1706.  
  1707.                        ################################
  1708.                        # End of man pages compressing #
  1709. ##############################################################################
  1710.  
  1711.  
  1712. # Now we get the TRUE list of files from the directory listing (kind of)
  1713. # of the BUILD_DIR. This is the true one simply because THESE are the files
  1714. # that will actually get packaged.
  1715.  
  1716.  
  1717. echo
  1718. echogn "Building file list..."
  1719. rm ${TMP_DIR}/newfiles
  1720. cd $BUILD_DIR
  1721. $TAR -cpf -  . | $TAR -f - -t 2>&1 | sed -e 's#^\./#/#' | egrep -v "^/$" > ${TMP_DIR}/newfiles
  1722. okfail
  1723.  
  1724.  
  1725. # Do we have a postinstall script?
  1726. PINST_EXISTS=0
  1727. [ -f ${DIRECTORIO_FUENTE}/postinstall-pak ] && PINST_EXISTS=1
  1728.  
  1729. ##############################################################################
  1730.                          # Identify shared libraries # 
  1731.                          #############################
  1732.  
  1733. if [ $ADD_SO -eq 1 ]; then
  1734.  
  1735. # Here we identify the shared libraries locations so we can add them
  1736. # to /etc/ld.so.conf file if they're not already there. This will be done
  1737. # in the postinstall script.
  1738.  
  1739. cat ${TMP_DIR}/newfiles | while read libfile; do
  1740.   FILETYPE=`file $libfile` 
  1741.   if echo /$FILETYPE | grep -e ".*ELF.*hared.*bject" &> /dev/null; then
  1742.      echo `dirname $libfile` >> ${TMP_DIR}/libdirs
  1743.   fi
  1744. done
  1745.  
  1746. # Did we find any libdirs?
  1747. if [ -f ${TMP_DIR}/libdirs ]; then
  1748.  
  1749.  echo
  1750.  echog "Shared libraries found. Adding them to the postinstall script."
  1751.  # If we have a pre-existing postinstall-pak we save it
  1752.  
  1753.  if [ $PINST_EXISTS -gt 0 ]; then
  1754.     mv ${DIRECTORIO_FUENTE}/postinstall-pak ${DIRECTORIO_FUENTE}/postinstall-pak.tmp 
  1755.     PINST_EXISTS=1
  1756.  fi
  1757.  
  1758.  if ! [ $PINST_EXISTS -gt 0 ]; then
  1759.     cat << EOF > ${DIRECTORIO_FUENTE}/postinstall-pak
  1760. #!/bin/sh
  1761. #
  1762. # postinstall script, created by checkinstall-${CHECKINSTALL_VERSION}
  1763. #
  1764. EOF
  1765.  fi
  1766.  
  1767.  echo "echo" >>  ${DIRECTORIO_FUENTE}/postinstall-pak
  1768.  
  1769.  cat ${TMP_DIR}/libdirs | while read libdir; do
  1770.    (
  1771.     echo "if ! egrep \"^/${libdir} *$\" /etc/ld.so.conf &> /dev/null; then"
  1772.     echo "   echo \"Adding \"/$libdir\" to /etc/ld.so.conf\"" 
  1773.     echo "   echo /$libdir >> /etc/ld.so.conf"
  1774.     echo fi
  1775.    ) >> ${DIRECTORIO_FUENTE}/postinstall-pak
  1776.  done
  1777.  
  1778.  echo ldconfig >> ${DIRECTORIO_FUENTE}/postinstall-pak
  1779.  
  1780.  # If we had an existing postinstall-pak, append it to the new one
  1781.  
  1782.  if [ -f ${DIRECTORIO_FUENTE}/postinstall-pak.tmp ]; then
  1783.     cat ${DIRECTORIO_FUENTE}/postinstall-pak.tmp >> ${DIRECTORIO_FUENTE}/postinstall-pak
  1784.  fi
  1785.  
  1786. fi  # End of did we find any libdirs?
  1787.  
  1788. fi
  1789.  
  1790.                        ####################################
  1791.                        # End of Identify shared libraries # 
  1792. ##############################################################################
  1793.  
  1794.  
  1795. cd $DIRECTORIO_FUENTE
  1796.  
  1797. FAILED=0
  1798.  
  1799. case $INSTYPE in
  1800.  
  1801. ##############################################################################
  1802.                     # Create Slackware compatible tarball #
  1803.                     #######################################
  1804.  
  1805.  
  1806. s|S)  
  1807.  
  1808.  
  1809. # The new Slackware naming scheme
  1810. SLACK_PKG_BASENAME="${PKG_BASENAME}-${ARCHITECTURE}-${RELEASE}"
  1811.  
  1812. FAILED=0
  1813.  
  1814. # If we're not installing the package then there is no problem if 
  1815. # installpkg is not in our execution path
  1816.  
  1817. if [ $INSTALL -gt 0 ]; then
  1818.    # Verify that we have the "installpkg" command in our path 
  1819.  
  1820.    INSTALLPKG_PATH=`which installpkg 2> /dev/null`
  1821.  
  1822.    if ! [ -x "$INSTALLPKG_PATH" ]; then
  1823.       echo
  1824.       echog "*** The \"installpkg\" program is not in your PATH!"
  1825.       echo
  1826.       echog "*** Slackware package creation aborted"
  1827.       FAILED=1
  1828.    fi
  1829. fi
  1830.  
  1831. if ! [ $FAILED -gt 0 ]; then
  1832.  
  1833. # Create the Slackware installation script
  1834.  
  1835. echo
  1836. echogn "Preparing Slackware install directory..."
  1837. mkdir -p ${BUILD_DIR}/install
  1838. touch ${BUILD_DIR}/install/doinst.sh
  1839. okfail
  1840.  
  1841. echo
  1842. echogn "Writing package description..."
  1843.  
  1844. # If we're building for Slackware 8.1+, then we use the new description
  1845. # file format
  1846.  
  1847. if [ $NEW_SLACK -gt 0 ]; then
  1848.  
  1849. cat << EOF > ${BUILD_DIR}/install/slack-desc
  1850. # HOW TO EDIT THIS FILE:
  1851. # The "handy ruler" below makes it easier to edit a package description.  Line
  1852. # up the first '|' above the ':' following the base package name, and the '|' on
  1853. # the right side marks the last column you can put a character in. You must make
  1854. # exactly 11 lines for the formatting to be correct.  It's also customary to
  1855. # leave one space after the ':'.
  1856.  
  1857. EOF
  1858.  
  1859. # Calculate the spaces before the "handy-ruler"
  1860. HR_SPACES=`echo $NAME | wc -c| awk '{ for (i=1;substr ($0,i,1) ~ /[[:blank:]]/ ;i++); print substr ($0,i);}'`
  1861.  
  1862.  
  1863. awk -v S=$HR_SPACES 'BEGIN {ORS=""; for (i=1; i < S; i++) print " ";}' >> ${BUILD_DIR}/install/slack-desc
  1864.  
  1865. echo "|-----handy-ruler------------------------------------------------------|" >> ${BUILD_DIR}/install/slack-desc
  1866.  
  1867.  
  1868. # Add the prefixed description
  1869.  cat description-pak | while read line; do
  1870.     echo "$NAME: $line" >> ${BUILD_DIR}/install/slack-desc
  1871.  done
  1872.  
  1873. okfail
  1874.  
  1875. # End of NEW_SLACK block
  1876.  
  1877. else 
  1878.  
  1879. #
  1880. # Generate the description-installing doinst.sh
  1881. #
  1882.  
  1883. if [ $AUTODOINST -eq 1 ]; then
  1884.    echo "PACKAGE DESCRIPTION:" > ${BUILD_DIR}/install/description
  1885.    cat description-pak | while read line; do
  1886.       echo $line >> ${BUILD_DIR}/install/description
  1887.    done
  1888.    okfail 
  1889.  
  1890.    echo
  1891.    echogn "Writing Slackware install script..."
  1892.    cat << EOF >> ${BUILD_DIR}/install/doinst.sh
  1893. # doinst.sh, auto-generated by checkinstall-${CHECKINSTALL_VERSION}
  1894. #
  1895.  
  1896. echo 
  1897. cat /install/description
  1898.  
  1899. sed '/PACKAGE LOCATION/r /install/description' < "/var/log/packages/$SLACK_PKG_BASENAME" > description.tmp
  1900. mv description.tmp "/var/log/packages/${SLACK_PKG_BASENAME}"
  1901. rm /install/description
  1902.  
  1903. EOF
  1904.    okfail
  1905. fi
  1906.  
  1907. fi # End of description creation
  1908.  
  1909. # If we have a Slackware install script already, add it to this one
  1910. # and force an interactive slackware install script
  1911. for file in postinstall-pak install-pak; do
  1912.    if [ -f $file ]; then
  1913.       INSTALL_PAK=${file}
  1914.    fi
  1915. done
  1916. if [ -f "$INSTALL_PAK" ]; then 
  1917.    echo
  1918.    # We want to say this only if we actually had a preexisting postinstall-pak
  1919.    if [ $PINST_EXISTS -gt 0 ]; then
  1920.       echogn "Appending your script to the main install script..."
  1921.       cat $INSTALL_PAK >> ${BUILD_DIR}/install/doinst.sh
  1922.       okfail
  1923.       echo
  1924.    else
  1925.       cat $INSTALL_PAK >> ${BUILD_DIR}/install/doinst.sh
  1926.    fi
  1927.    SHOW_SLACK_INSTALL=1
  1928. fi
  1929.  
  1930.  
  1931. echo
  1932. echogn "Creating package ${SLACK_PKG_BASENAME}..."
  1933.  
  1934. cd $BUILD_DIR
  1935. chmod 755 $BUILD_DIR
  1936.  
  1937. # Make the "TAR" variable available to MAKEPKG
  1938. export TAR
  1939.  
  1940. if [ $SHOW_MAKEPKG -gt 0 ]; then
  1941.    $MAKEPKG $MAKEPKG_FLAGS "${SLACK_PKG_BASENAME}.tgz"
  1942.    okfail
  1943. else
  1944.    $MAKEPKG $MAKEPKG_FLAGS "${SLACK_PKG_BASENAME}.tgz" &> /dev/null
  1945.    okfail
  1946. fi
  1947.  
  1948. mv "${SLACK_PKG_BASENAME}.tgz" "$DIRECTORIO_FUENTE"
  1949.  
  1950. #
  1951. # If requested, we install the package to register it in Slackware's
  1952. # installed packages list so we can list it's contents with pkgtool 
  1953. # or remove it with removepkg
  1954. #
  1955.  
  1956. if [ "$INSTALL" = "1" ]; then
  1957.  
  1958.    # Go back to where we started
  1959.    cd "$DIRECTORIO_FUENTE"
  1960.    
  1961.    echo
  1962.    
  1963.    if [ $SHOW_SLACK_INSTALL -eq 0 ]; then
  1964.       echogn "Installing package..."
  1965.       installpkg "${SLACK_PKG_BASENAME}.tgz" &> ${TMP_DIR}/slackinstall.log
  1966.       okfail
  1967.       [ $? -gt 0 ] && FAILED=1
  1968.    
  1969.    else
  1970.    echog "========================= Installation results ==========================="
  1971.       echo
  1972.       installpkg "${SLACK_PKG_BASENAME}.tgz" 
  1973.       if [ $? -gt 0 ]; then
  1974.          FAILED=1
  1975.       else
  1976.          echo
  1977.       echog "======================== Installation successful =========================="
  1978.       fi
  1979.    fi
  1980.    
  1981.    if [ $FAILED -eq 1 ]; then
  1982.       echo
  1983.       echog "*** Failed to install the package"
  1984.       echo
  1985.       if [ $SHOW_SLACK_INSTALL -eq 0 ]; then
  1986.          echogn "Do you want to see the log file? "
  1987.          if yorn ; then
  1988.             $PAGER ${TMP_DIR}/slackinstall.log
  1989.             cleanup
  1990.             exit 1
  1991.          fi
  1992.       fi
  1993.    fi
  1994.  
  1995. else
  1996.         echo
  1997.         echog "NOTE: The package will not be installed."
  1998. fi
  1999.  
  2000.  
  2001. PKG_LOCATION="${DIRECTORIO_FUENTE}/${SLACK_PKG_BASENAME}.tgz"
  2002. INSTALLSTRING="installpkg ${SLACK_PKG_BASENAME}.tgz"
  2003. REMOVESTRING="removepkg ${SLACK_PKG_BASENAME}"
  2004.  
  2005. fi
  2006. ;;
  2007.  
  2008.  
  2009.                        #################################
  2010.                        # End Slackware package section #
  2011. ##############################################################################
  2012.  
  2013.  
  2014. ##############################################################################
  2015.                           # RPM package installation #
  2016.                           ############################
  2017.  
  2018.  
  2019. r|R)
  2020.  
  2021.  
  2022. FAILED=0
  2023.  
  2024. # Verify that we have the rpm command in our path
  2025.  
  2026. RPM_PATH=`which rpm 2> /dev/null`
  2027.  
  2028. if ! [ -x "$RPM_PATH" ]; then
  2029.    echo
  2030.    echog "*** The \"rpm\" program is not in your PATH!"
  2031.    echo
  2032.    echog "*** RPM package creation aborted"
  2033.    FAILED=1
  2034. fi
  2035.    
  2036. if ! [ $FAILED -gt 0 ]; then
  2037.  
  2038. # Identify the rpm version
  2039.  
  2040. RPM_VERSION=`rpm --version | awk '{ print $3 }'`
  2041. RPM_MAJOR_VERSION=`echo $RPM_VERSION | cut -f1 -d"."`
  2042. RPM_MINOR_VERSION=`echo $RPM_VERSION | cut -f2 -d"."`
  2043. RPM_PATCH_LEVEL=`echo $RPM_VERSION | cut -f3 -d"."`
  2044.  
  2045. if [ "$RPM_PATCH_LEVEL" = "" ]; then 
  2046.    RPM_PATCH_LEVEL=0
  2047. fi
  2048.  
  2049.  
  2050. if [ $DEBUG -gt 0 ]; then
  2051.    echo "debug: RPM_VERSION=${RPM_VERSION}"
  2052.    echo "debug: RPM_MAJOR_VERSION=$RPM_MAJOR_VERSION"
  2053.    echo "debug: RPM_MINOR_VERSION=$RPM_MINOR_VERSION"
  2054.    echo "debug: RPM_PATCH_LEVEL=$RPM_PATCH_LEVEL"
  2055.    echo "debug: RPM_IU=$RPM_IU"
  2056. fi
  2057.  
  2058. # AFAIK, the only rpm versions that accept
  2059. # "--target=arch" instead of "--target arch"
  2060. # are 3.x < version < 4.0.3
  2061.  
  2062. if [ $RPM_MAJOR_VERSION -eq 4 -a $RPM_PATCH_LEVEL -lt 3 ]; then
  2063.    RPM_TARGET_FLAG="--target="
  2064. else
  2065.    RPM_TARGET_FLAG="--target "
  2066. fi
  2067.  
  2068. # rpmbuild seems to exist only in RPM 4
  2069.  
  2070. if [ $RPM_MAJOR_VERSION -eq 4 ]; then
  2071.    RPMBUILD="rpmbuild"
  2072. else
  2073.    RPMBUILD="rpm"
  2074. fi
  2075.  
  2076. if [ "$RPMBUILD" = "rpmbuild" -a ! -x "`which rpmbuild 2> /dev/null`" ]; then
  2077.    echo
  2078.    echo "*** The \"rpmbuild\" program is not in your PATH!"
  2079.    echo
  2080.    echo "*** RPM package creation aborted"
  2081.    FAILED=1
  2082. fi
  2083.    
  2084. if ! [ $FAILED -gt 0 ]; then
  2085.  
  2086.  
  2087. # Find out the RPM source directory path
  2088.  
  2089. if ! [ "$RPMSOURCEDIR" ]; then
  2090.    if [ $RPM_MAJOR_VERSION -eq 3 -a $RPM_PATCH_LEVEL -ge 3 -o $RPM_MAJOR_VERSION -gt 3 ]; then
  2091.       RPMSOURCEDIR="`rpm --eval=%_topdir`"
  2092.    else
  2093.       RPMSOURCEDIR="NOT-FOUND"
  2094.       for directory in packages OpenLinux redhat RedHat rpm RPM "" ; do
  2095.          [ -d /usr/src/${directory}/SOURCES ] && RPMSOURCEDIR="/usr/src/${directory}"
  2096.       done
  2097.    fi
  2098. fi
  2099.  
  2100. [ $DEBUG -gt 0 ] && echo "debug: RPMSOURCEDIR=$RPMSOURCEDIR"
  2101.  
  2102.  
  2103. while ! [ -d "$RPMSOURCEDIR/SOURCES" ]; do
  2104.    echo
  2105.    echogn "%s has no SOURCES directory. Please write the path to\nthe RPM source directory tree: " "$RPMSOURCEDIR"
  2106.    read RPMSOURCEDIR
  2107.    ! [ "$RPMSOURCEDIR" ] && RPMSOURCEDIR="NOT-FOUND"
  2108. done
  2109.  
  2110.    
  2111. # We'll write a basic spec file
  2112.  
  2113. if ! [ -f "$SPEC_PATH" ]; then
  2114.  
  2115. # If the buildroot path has spaces then we'll use the BUILD_DIR instead.
  2116. # rpm can't have a buildroot path with spaces in it (Bug?)
  2117. #
  2118. # This is obviously a hack, I hope we can do it the right way when rpm is
  2119. # fixed.
  2120.  
  2121. if ( echo $DIRECTORIO_FUENTE | grep " " &> /dev/null ); then
  2122.    BROOTPATH="${DIRECTORIO_FUENTE}/buildroot"
  2123. else
  2124.    BROOTPATH=$BUILD_DIR
  2125. fi
  2126.  
  2127. # Here comes the .spec file:
  2128.  
  2129.    cat > "$SPEC_PATH" << EOF
  2130. Summary:   $SUMMARY
  2131. Name:      $NAME
  2132. Version:   $VERSION
  2133. Release:   $RELEASE
  2134. License: $LICENSE
  2135. Packager:  checkinstall-$CHECKINSTALL_VERSION
  2136. Group:     $PKG_GROUP          
  2137. BuildRoot: $BROOTPATH
  2138. Provides:  $PROVIDES
  2139. Requires:  $REQUIRES,/bin/sh
  2140.  
  2141. %description
  2142. EOF
  2143.    cat description-pak >> "$SPEC_PATH"
  2144.  
  2145.  
  2146. # Use the preinstall-pak script if we have it
  2147. if [ -f preinstall-pak ]; then
  2148.    echo  >> "$SPEC_PATH" 
  2149.    echo '%pre' >> "$SPEC_PATH" 
  2150.    cat preinstall-pak  >> "$SPEC_PATH"
  2151. fi
  2152.  
  2153. # Use the postinstall-pak script if we have it
  2154. if [ -f postinstall-pak ]; then
  2155.    echo >> "$SPEC_PATH" 
  2156.    echo '%post' >> "$SPEC_PATH" 
  2157.    cat postinstall-pak  >> "$SPEC_PATH"
  2158. fi
  2159.  
  2160. # Use the preremove-pak script if we have it
  2161. if [ -f preremove-pak ]; then
  2162.    echo >> "$SPEC_PATH" 
  2163.    echo '%preun' >> "$SPEC_PATH" 
  2164.    cat preremove-pak  >> "$SPEC_PATH"
  2165. fi
  2166.  
  2167. # Use the postremove-pak script if we have it
  2168. if [ -f postremove-pak ]; then
  2169.    echo >> "$SPEC_PATH" 
  2170.    echo '%postun' >> "$SPEC_PATH" 
  2171.    cat postremove-pak  >> "$SPEC_PATH"
  2172. fi
  2173.  
  2174.    cat >> "$SPEC_PATH" << EOF
  2175.  
  2176. %files
  2177. EOF
  2178.  
  2179. # Prepare directories to be included in the .spec file
  2180. mv ${TMP_DIR}/newfiles ${TMP_DIR}/newfiles.tmp
  2181. cat ${TMP_DIR}/newfiles.tmp | while read line; do
  2182.    [ -d "${BUILD_DIR}/${line}" -o -L "${BUILD_DIR}/${line}" ] && echo -n "%dir " >> ${TMP_DIR}/newfiles
  2183.    echo "\"/${line}\"" >> ${TMP_DIR}/newfiles
  2184. done
  2185.  
  2186. # Append the file list to the .spec file
  2187. cat ${TMP_DIR}/newfiles >> "$SPEC_PATH" 
  2188. fi
  2189.  
  2190.  
  2191. # If requested with --review-spec, we run an editor on the .spec file
  2192. if [ $REVIEW_SPEC -gt 0 ]; then
  2193.    echo
  2194.    echog "You requested to review the .spec file for this package.\nNow you\'ll have the chance to review and optionally modify this file."
  2195.    echo
  2196.    echog "Press ENTER to continue."
  2197.    read junk
  2198.    $VISUAL "$SPEC_PATH" 
  2199. fi
  2200.  
  2201. BUILDROOT=`egrep '^[Bb]uild[Rr]oot' < "$SPEC_PATH" | cut -f2 -d:| sed 's/^ *//g'| sed 's/ *$//g'` # The sed commands remove leading/trailing whitespaces
  2202.  
  2203. # We make sure that we have a valid RELEASE number
  2204.  
  2205. ! [ "$RELEASE" ] && RELEASE=`egrep '^Release:' < "$SPEC_PATH"|cut -f2 -d: | awk '{ for (i=1;substr ($0,i,1) ~ /[[:blank:]]/ ;i++); print substr ($0,i); }'`
  2206.  
  2207. [ $DEBUG -gt 0 ] && echo "debug: BUILDROOT=$BUILDROOT"
  2208.  
  2209. ! [ -d "$BUILDROOT" ] &&  ln -s "$BUILD_DIR" "$BUILDROOT"
  2210.  
  2211. # We make sure that the architecture directory exists
  2212.  
  2213. ! [ -d "${RPMSOURCEDIR}/RPMS/${ARCHITECTURE}" ] && mkdir -p "${RPMSOURCEDIR}/RPMS/${ARCHITECTURE}"
  2214.  
  2215.  
  2216. mkdir "${TMP_DIR}/$PKG_BASENAME"
  2217. cd $TMP_DIR
  2218. $TAR -cz -f "${RPMSOURCEDIR}/SOURCES/${PKG_BASENAME}.tgz" "$PKG_BASENAME"
  2219. rm -rf "${TMP_DIR}/$PKG_BASENAME"
  2220. cd "$DIRECTORIO_FUENTE"
  2221.  
  2222. echo
  2223. echogn "Building RPM package..."
  2224. $RPMBUILD -bb ${RPM_TARGET_FLAG}${ARCHITECTURE} "$SPEC_PATH" &> ${TMP_DIR}/rpmbuild.log
  2225. okfail
  2226.  
  2227. if [ $? -gt 0 ]; then
  2228.    echo
  2229.    echog "*** Failed to build the package"
  2230.    echo
  2231.    echogn "Do you want to see the log file? "
  2232.    if yorn ; then
  2233.       $PAGER ${TMP_DIR}/rpmbuild.log
  2234.    fi
  2235.    FAILED=1
  2236. fi
  2237.  
  2238. RPMPKG="${RPMSOURCEDIR}/RPMS/${ARCHITECTURE}/${PKG_BASENAME}-${RELEASE}.${ARCHITECTURE}.rpm"
  2239.  
  2240. # Check for the old RPMFLAGS
  2241. if [ "$RPMFLAGS" ]; then
  2242.    echo
  2243.    echog "Warning: the use of RPMFLAGS is deprecated.\nWarning: You should now use RPM_FLAGS,\nWarning: please update your checkinstallrc file."
  2244. fi
  2245.  
  2246. if ! [ $FAILED -gt 0 ]; then 
  2247.    if [ "$INSTALL" = "1" ]; then
  2248.  
  2249.       echo
  2250.       echogn "Installing RPM package..."
  2251.       rpm -$RPM_IU $RPM_FLAGS "${RPMPKG}" &>  ${TMP_DIR}/rpminstall.log
  2252.       okfail
  2253.       if [ $? -gt 0 ]; then
  2254.          echo
  2255.          echog "*** Failed to install the package"
  2256.          echo
  2257.          echogn "Do you want to see the log file? "
  2258.          if yorn ; then
  2259.             $PAGER ${TMP_DIR}/rpminstall.log
  2260.          fi
  2261.          FAILED=1
  2262.       fi
  2263.    else
  2264.       echo
  2265.       echog "NOTE: The package will not be installed"
  2266.    fi
  2267. fi
  2268.    
  2269. if ! [ $FAILED -gt 0 ]; then
  2270.    PKG_LOCATION="$RPMPKG"
  2271.    INSTALLSTRING="rpm -i `basename \"$RPMPKG\"`"
  2272.    REMOVESTRING="rpm -e ${PKG_BASENAME}-${RELEASE}"
  2273. fi
  2274.    
  2275.    
  2276. fi  # End of the "no rpmbuild in the path" if
  2277. fi  # End of the "no rpm in the path" if
  2278.  
  2279. ;;
  2280.  
  2281.                        #################################
  2282.                        #    End RPM package section    #
  2283. ##############################################################################
  2284.  
  2285.  
  2286.  
  2287. ##############################################################################
  2288.                         # Debian  package installation #
  2289.                         ################################
  2290.  
  2291.  
  2292. d|D)
  2293.  
  2294. # As we said before:
  2295. PKG_BASENAME=$NAME
  2296. # maybe PKG_BASENAME should be defined locally for all the install
  2297. # types, and not only on debian...
  2298.  
  2299. FAILED=0
  2300.  
  2301.  
  2302. # Verify that we have the dpkg command in our path
  2303.  
  2304. DPKG_PATH=`which dpkg 2> /dev/null`
  2305.  
  2306. if ! [ -x "$DPKG_PATH" ]; then
  2307.    echo
  2308.    echog "*** The \"dpkg\" program is not in your PATH!"
  2309.    echo
  2310.    echog "*** Debian package creation aborted"
  2311.    FAILED=1
  2312. fi
  2313.    
  2314. if ! [ $FAILED -gt 0 ]; then
  2315.  
  2316. cd "$DIRECTORIO_FUENTE"
  2317.  
  2318. # We'll write a basic Debian control file
  2319.  
  2320.  
  2321. mkdir $BUILD_DIR/DEBIAN
  2322.  
  2323. cat << EOF >> $BUILD_DIR/DEBIAN/control
  2324. Package: $PKG_BASENAME
  2325. Priority: extra
  2326. Section: $PKG_GROUP
  2327. Installed-Size: `du -s $BUILD_DIR | awk '{print $1}'`
  2328. Maintainer: $MAINTAINER
  2329. Architecture: $ARCHITECTURE
  2330. Version: ${VERSION}-${RELEASE}
  2331. Depends: $REQUIRES
  2332. Description: $SUMMARY
  2333. EOF
  2334.  
  2335. # Add the description
  2336. cat "$DIRECTORIO_FUENTE/description-pak"| egrep -v "$SUMMARY|^[     ]*$" | while read line; do
  2337.    echo " "$line >> $BUILD_DIR/DEBIAN/control
  2338. done
  2339.  
  2340.  
  2341. # Use the preinstall-pak script if we have it
  2342. if [ -f preinstall-pak ]; then
  2343.    cat preinstall-pak > $BUILD_DIR/DEBIAN/preinst
  2344.    chmod 755 $BUILD_DIR/DEBIAN/preinst
  2345. fi
  2346.  
  2347. # Use the postinstall-pak script if we have it
  2348. if [ -f postinstall-pak ]; then
  2349.    cat postinstall-pak > $BUILD_DIR/DEBIAN/postinst
  2350.    chmod 755 $BUILD_DIR/DEBIAN/postinst
  2351. fi
  2352.  
  2353. # Use the preremove-pak script if we have it
  2354. if [ -f preremove-pak ]; then
  2355.    cat preremove-pak > $BUILD_DIR/DEBIAN/prerm
  2356.    chmod 755 $BUILD_DIR/DEBIAN/prerm
  2357. fi
  2358.  
  2359. # Use the postremove-pak script if we have it
  2360. if [ -f postremove-pak ]; then
  2361.    cat postremove-pak > $BUILD_DIR/DEBIAN/postrm
  2362.    chmod 755 $BUILD_DIR/DEBIAN/postrm
  2363. fi
  2364.  
  2365.  
  2366. # The package will be saved here:
  2367. DEBPKG="${DIRECTORIO_FUENTE}/${NAME}_${VERSION}-${RELEASE}_${ARCHITECTURE}.deb"
  2368. # This one is for 2.2 "Potato" (or older) style packages
  2369. #DEBPKG="${DIRECTORIO_FUENTE}/${NAME}_${VERSION}-${RELEASE}.deb"
  2370.  
  2371. if [ $DEBUG -gt 0 ]; then
  2372.   echo
  2373.   echo debug: PKG_BASENAME=${PKG_BASENAME}
  2374.   echo debug: BUILD_DIR=${BUILD_DIR}
  2375.   echo debug: DEBPKG=${DEBPKG}
  2376.   echo debug: dpkg command:
  2377.   echo "   \"dpkg-deb -b $BUILD_DIR $DEBPKG &> ${TMP_DIR}/dpkgbuild.log\""
  2378. fi
  2379.  
  2380. # If requested with --review-control, we run an editor on the control file
  2381. if [ $REVIEW_CONTROL -gt 0 ]; then
  2382.    echo
  2383.    echog "You requested to review the control file for this package.\nNow you'll have the chance to review and optionally modify this file."
  2384.    echo
  2385.    echog "Press ENTER to continue."
  2386.    read junk
  2387.    $VISUAL ${BUILD_DIR}/DEBIAN/control
  2388. fi
  2389.  
  2390. echo
  2391. echogn "Building Debian package..."
  2392. dpkg-deb -b $BUILD_DIR "$DEBPKG" &> ${TMP_DIR}/dpkgbuild.log
  2393. okfail
  2394.       
  2395. if [ $? -gt 0 ]; then
  2396.    echo
  2397.    echog "*** Failed to build the package"
  2398.    echo
  2399.    echogn "Do you want to see the log file? "
  2400.    if yorn ; then
  2401.       $PAGER ${TMP_DIR}/dpkgbuild.log
  2402.    fi
  2403.    FAILED=1
  2404. fi
  2405.  
  2406.  
  2407. if ! [ $FAILED -gt 0 ]; then
  2408.    if [ "$INSTALL" = "1" ]; then
  2409.  
  2410.       echo
  2411.       echogn "Installing Debian package..." 
  2412.       dpkg -i $DPKG_FLAGS "$DEBPKG" &>  ${TMP_DIR}/dpkginstall.log
  2413.       okfail
  2414.       if [ $? -gt 0 ]; then
  2415.          echo
  2416.          echog "*** Failed to install the package"
  2417.          echo
  2418.          echogn "Do you want to see the log file? "
  2419.          if yorn ; then
  2420.             $PAGER ${TMP_DIR}/dpkginstall.log
  2421.          fi
  2422.          FAILED=1
  2423.       fi
  2424.    else
  2425.       echo
  2426.       echog "NOTE: The package will not be installed"
  2427.    fi
  2428. fi
  2429.  
  2430. if ! [ $FAILED -gt 0 ]; then
  2431.    PKG_LOCATION="$DEBPKG"
  2432.    INSTALLSTRING="dpkg -i `basename \"$DEBPKG\"`"
  2433.    REMOVESTRING="dpkg -r ${PKG_BASENAME}"
  2434. fi
  2435.  
  2436.  
  2437. fi
  2438.  
  2439. ;;
  2440.  
  2441.  
  2442.                        ################################
  2443.                        #  End Debian package section  #
  2444. ##############################################################################
  2445.  
  2446.  
  2447. esac
  2448.  
  2449. # If we have a package repository set, move the package there
  2450.  
  2451. if ! [ $FAILED -gt 0 ]; then
  2452.  
  2453.    if [ "$PAK_DIR" ]; then
  2454.       if ! [ -d "$PAK_DIR" ]; then
  2455.          echo
  2456.          echogn "The package storage directory [ %s ]\ndoesn\'t exist. Do you want to create it?" "$PAK_DIR"
  2457.          if yorn ; then
  2458.             echo
  2459.             echogn "Creating package storage directory..."
  2460.             mkdir -p "$PAK_DIR" &> ${TMP_DIR}/mkpakdir.log
  2461.             okfail 
  2462.             if [ $? -gt 0 ]; then
  2463.                echo 
  2464.                echog "*** Unable to create %s" "$PAK_DIR"
  2465.                echo "*** `cat ${TMP_DIR}/mkpakdir.log`"
  2466.                echo
  2467.             fi
  2468.          fi
  2469.       fi
  2470.       if [ -d "$PAK_DIR" ]; then 
  2471.          echo
  2472.          echogn "Transferring package to %s..." "$PAK_DIR"
  2473.          mv "$PKG_LOCATION" "${PAK_DIR}" &> $TMP_DIR/transfer.log
  2474.          okfail
  2475.          if [ $? -gt 0 ]; then
  2476.             echo
  2477.             echogn "*** Transfer failed:"
  2478.             cat $TMP_DIR/transfer.log
  2479.             echo
  2480.          else
  2481.             # Update the package location
  2482.             PKG_LOCATION="${PAK_DIR}/`basename \"$PKG_LOCATION\"`"
  2483.          fi
  2484.       else 
  2485.          echo
  2486.          echog "There\'s no package storage directory, the package\nwill be stored at the default location."
  2487.       fi
  2488.    fi
  2489. fi
  2490.  
  2491. #
  2492. # Remove trash from TMP_DIR
  2493. #
  2494.  
  2495. echo 
  2496. echogn "Erasing temporary files..."
  2497.  
  2498. # Preserve the Debian control file if debug is on
  2499. if [ $DEBUG -gt 0 ]; then
  2500.    if [ -d ${BUILD_DIR}/DEBIAN ]; then
  2501.        mv ${BUILD_DIR}/DEBIAN $TMP_DIR
  2502.    fi
  2503. fi
  2504.  
  2505. [ $DEBUG -lt 2 ] && rm -rf ${BUILD_DIR}
  2506. rm -f checkinstall-debug*
  2507. rm -f "$BUILDROOT"
  2508. rm -f "${RPMSOURCEDIR}/SOURCES/${PKG_BASENAME}.tgz"
  2509. okfail
  2510.  
  2511. # Delete doc-pak directory
  2512. if [ $DEL_DOCPAK -gt 0 ]; then
  2513.    echo
  2514.    echogn "Deleting doc-pak directory..."
  2515.    rm -rf doc-pak
  2516.    okfail
  2517. fi
  2518.  
  2519. # Preserve the spec file if debugging is on
  2520. [ $DEBUG -gt 0 ] && [ -f "$SPEC_PATH" ] && cp "$SPEC_PATH" $TMP_DIR
  2521.  
  2522. # Delete spec file
  2523.  [ $DEL_SPEC -gt 0 ] && rm -f "$SPEC_PATH"
  2524.  
  2525. # Delete the package description file
  2526.  [ $DEL_DESC -gt 0 ] && rm -f description-pak
  2527.  
  2528.  
  2529. # If we had a pre-existing postinstall-pak, we keep it as it was.
  2530.  
  2531. # If PINST_EXISTS=0 and there is a postinstall-pak file, then
  2532. # it's the one we created and has to be deleted 
  2533. if [ $PINST_EXISTS -eq 0 ]; then  
  2534.    rm -f ${DIRECTORIO_FUENTE}/postinstall-pak
  2535. fi
  2536.  
  2537. if [ -f ${DIRECTORIO_FUENTE}/postinstall-pak.tmp ]; then
  2538.    mv ${DIRECTORIO_FUENTE}/postinstall-pak.tmp ${DIRECTORIO_FUENTE}/postinstall-pak
  2539. fi
  2540.  
  2541.  
  2542. # If we have a backup, pack it up
  2543.  
  2544. rm -rf ${TMP_DIR}/BACKUP/no-backup &> /dev/null
  2545. ls ${TMP_DIR}/BACKUP/* &> /dev/null
  2546. if [ $? -eq 0 ]; then
  2547.    cd ${TMP_DIR}/BACKUP
  2548.    echo
  2549.    echogn "Writing backup package..."
  2550.    $TAR -cpf - . | gzip -9 > "${DIRECTORIO_FUENTE}/backup-`date +%m%d%Y%H%M`-pre-${PKG_BASENAME}.tgz"
  2551.    okfail
  2552. fi
  2553.  
  2554.  
  2555. if [ $DEBUG -eq 0 ]; then
  2556.    echo
  2557.    echogn "Deleting temp dir..."
  2558.    rm -rf ${TMP_DIR}
  2559.    okfail
  2560.    echo
  2561. else
  2562.    echo
  2563.    echogn "Building debug information package..."
  2564.    cd ${TMP_DIR}
  2565.    echo `uname -a` > sysinfo
  2566.    echo `rpm --version` >> sysinfo
  2567.    $TAR -cpzvf "${DIRECTORIO_FUENTE}/checkinstall-debug.$$.tgz" * &> /dev/null
  2568.    okfail
  2569. fi
  2570.  
  2571.  
  2572. if ! [ $FAILED -gt 0 ]; then
  2573.  
  2574.    if [ "${INSTALL}" = "1" ]; then
  2575.  
  2576.       echo
  2577.       echo '**********************************************************************'
  2578.       echo
  2579.       echog " Done. The new package has been installed and saved to\n\n %s\n\n You can remove it from your system anytime using: \n\n      %s" "$PKG_LOCATION"  "$REMOVESTRING"
  2580.       echo
  2581.       echo '**********************************************************************'
  2582.       echo
  2583.  
  2584.    else
  2585.  
  2586.       echo
  2587.       echo '**********************************************************************'
  2588.       echo
  2589.       echog " Done. The new package has been saved to\n\n %s\n You can install it in your system anytime using: \n\n      %s" "$PKG_LOCATION" "$INSTALLSTRING"
  2590.       echo
  2591.       echo '**********************************************************************'
  2592.       echo
  2593.  
  2594.    fi
  2595.       
  2596. fi
  2597.  
  2598.  
  2599.  
  2600.  
  2601.